【发布时间】:2016-11-14 18:02:25
【问题描述】:
我创建了一个新对象,在该对象中我有几个对象变量,但未正确设置事件(可选)对象。当事件选项卡在构建函数中调用它时,它会出现未定义,我猜这可能与它可能是异步的有关。下面是我的对象和调用,也是我在引用对象时得到的。
我无法弄清楚为什么它会像在调用构建函数之前设置的那样未定义。
更新:这个小提琴有被调用的确切代码。 https://jsfiddle.net/trickell/Leg1gqkz/2/
问题出在 checkEvents() 方法中。
var Wizard = function(id, events) {
this.activeTab = '';
this.prevTab = '';
this.nextTab = '';
this.events = (events) ? events : {}; // Optional events object. User may define events based on tab. (ex. "tabName" : function(){})
console.log(this.events); // Returns object with no keys
this.build(id);
return this;
}
Wizard.prototype.build = function(id){
var tab = id,
events = this.events;
// **** This is what's showing up as undefined!!! *****/
console.log(events.cardInfo);
}
(function($, undefined){
var wiz = new Wizard($('#package_wizard'),
{
cardInfo : function() {
alert('hello world');
}
});
})(jQuery);
【问题讨论】:
标签: javascript object prototype undefined