![](/img/trans.png)
[英]Firefox doesn't respect Object.defineProperty() from a Greasemonkey script?
[英]Getter function from defineProperty doesn't return selector
我嘗試通過對象的getter函數返回一個選擇器,該選擇器在創建后被初始化。 為什么我的財產“未定義”? 不能把我的頭纏住...
http://jsfiddle.net/micka/fBPxG/
HTML:
<div class="current"></div>
JS:
var Slider = {
init: function (config) {
this.config = config;
console.log('this should be the div with a class of current', this.currentSelector)
}
};
Slider.init({
mySelector: $('div')
});
Object.defineProperty(Slider, 'currentSelector', {
get: function () {
return $('.current', this.config.mySelector);
}
});
Object.defineProperty(Slider, 'currentSelector', {
get: function () {
return $('.current', this.config.mySelector);
}
});
在Slider.init({...})
之后定義Slider.init({...})
在觸發Slider.init時,尚未定義currentSelector屬性並返回未定義。
解決方案:請上移Object.defineProperty
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.