开发者

jQuery Widget Factory - _setOption method

I wonder if anyone can advise whether it's considered 'standard' to provide _setOption functionality for every option available at instantiation when using jQuery UIs widget factory?

The reason I ask is because I'm finding myself adding a shed load of bloat to my widget just to allow option changes that, in all honesty, I can't see being used开发者_开发百科 after instantiation?

Any advice?

Rich


No, the options get copied in automatically by the framework.

However I think it is a good practice to set a default for all the options possible in the class e.g.

options: {
    errorColor: '#7f0000;',
    focusCallback: false,
}

So you can always reference the option value directly rather than calling:

if (typeof this.options.errorColor != "undefined") {
    //use default color '#7f0000;'
}
else{
    //use this.options.errorColor
}


Yes.

http://forum.jquery.com/topic/widget-factory-setoption - "making it robust post-init makes it robust at-init."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜