我尝试通过一个对象的 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);
}
});