我需要buttons从函数访问属性,enableNav但我的问题是我不能因为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')
});
})();