a glob of nerdishness » Javascript http://www.extinguishedscholar.com/wpglob Powered by work over time. Sun, 26 Feb 2012 06:22:42 +0000 http://wordpress.org/?v=2.8.4 en hourly 1 [widget setPreference: for:] is not JavaScript! http://www.extinguishedscholar.com/wpglob/?p=259 http://www.extinguishedscholar.com/wpglob/?p=259#comments Sat, 15 Sep 2007 20:08:50 +0000 natevw http://www.extinguishedscholar.com/wpglob/?p=259 Widgets can get and set persistent preferences without much hassle. It’s as easy as calling widget.preferenceForKey(key), which will return the value set for the key.

However, sometimes this doesn’t seem to work, because the developer swapped the arguments when setting. The correct order widget.setPreferenceForKey(value, key) is swapped from, say, element.setAttribute(name,value). This one has gotten me way too many times when developing Dashboard widgets.

How did this bizarre ordering come about? I’m guessing it’s because the widget object is actually written as an Objective-C plugin and the developers felt obligated to make the method idiomatic in that language: (void)setPreference:(NSString*)value forKey:(NSString*)key. But the function name is rewritten between Obj-C and JS anyway — I wish they could have broken the idiom a bit and used (void)setPreference:(NSString*)key toValue:(NSString*)value as the method signature, for the sake of the end users.

(Updated to fix method names from original post.)

]]>
http://www.extinguishedscholar.com/wpglob/?feed=rss2&p=259 0