在jquery中创建插件时,我正在创建我的可配置设置:
var settings = $.extend( {
'setting_one' : 'setting_one_value',
'setting_two' : 'setting_two_value'
}, options)
我想要做的是创建另一个设置,该设置取决于setting_one或setting_two的值。
例如:
var settings = $.extend( {
'setting_one' : 'setting_one_value',
'setting_two' : 'setting_two_value',
'setting_three' : setting_one + setting_two,
}, options)
我该怎么做?
答案 0 :(得分:1)
我认为你可以存档的唯一方法是通过以下设置三:
var defaults = {
one: 1,
two: 2
};
var options = {
one: 2,
two: 4
};
var settings = $.extend({}, defaults, options);
settings.three = settings.one + settings.two;
这是确保您获得正确数据为3的唯一方法,例如,如果选项没有属性two
:
var options = {
one: 2
}
settings.three
将为4
答案 1 :(得分:0)
var ops = (function (){
var one, two, three
one = 'foo'
two = 'baz'
three = one + ' ' + two
return {
one: one,
two: two,
three: three
}
}())
var o = $.extend(ops, options)