Skip navigation.

exploreopera

| Help

Sign up | Help

Benjamin Joffe

Widget setPreferenceForKey(); enhancement

As you may know, when setting and retrieving stored values in widgets using the two functions setPreferenceForKey and preferenceForKey you can only use a string as an argument. I have created a library which acts as a wrapper for these functions, extending their support to:
  • String
  • Boolean
  • Number
  • Date
  • Array
  • Object
Best of all, the arrays and objects can be of any depth and even allow cyclic (or recursive) references. All you have to do is download the file below and load it in your page before your script executes.

Download the library

Notes
  • If you try to call a preference which has not been set then the null value will be returned instead of the usual empty string.
  • Attempting to save a function will instead save the string "[Function]".
Updates
  • 4 Jun 2007
    Fixed a bug regarding some recursive patterns.
    Added a licence.

Why?Big Yawn

Comments

avatar
Very good job Benjamin, I'll try to make a good use of it, thanks!

By eestlane, # 27. May 2007, 10:17:22

avatar
Great! Just today is thinking about writting something similar, but not as generic... So, will try to use yours.

By FataL, # 17. November 2007, 05:48:14

avatar
Thanks for sharing. I like it

By auto-leasing, # 31. August 2008, 11:49:59

Write a comment

You must be logged in to write a comment. if you're not a registered member, please sign up.