0
需要將someObject.config.title
的值更新爲從click
事件中設置的值。我如何去做這件事?從專用內部函數更新變量值
也有一個單獨的問題,有什麼辦法可以設置$this
作爲一個全局變量,可以通過此對象的任何子功能訪問?
var someObject = {
config: {
title: ''
},
init: function() {
// Any way to set $this as a global var that can accessed through any of the child functions of this object?
var $this = this,
title = $this.config.title;
$('button').on('click' , function() {
title = 'yo, waz gud son!';
// This reference works
//$this.referenceTitle(title);
});
// This reference is undefined, need to update original value
$this.referenceTitle(title);
},
referenceTitle: function(arg) {
console.log(arg);
}
}
someObject.init();
試過了,沒有工作。即使在點擊按鈕後 – Shivam