1
我需要从功能enableNav
访问buttons
财产,但我的问题是,我不能因为this
参考点到enableNav
函数,而不是对象本身,如何正确获取buttons
?变量范围对象
(function() {
var MyCustomObject = {
init: function(config) {
this.myvar = config.myvar;
this.buttons = config.buttons;
this.enableNav();
},
enableNav: function() {
// need to use buttons here!!
}
};
MyCustomObject.init({
myVar: 3,
buttons: $('button')
});
})();
这只是不是真的:http://jsfiddle.net/KQfj9/ ...也许你需要在准备'$来包装这个(函数(){});' ? – mVChr