2012-07-28 27 views
1

我做goog.ui.Component的子类:为什么我的goog.ui.Component中没有定义`setModel()`?

/** 
* Renders the bottom pane. 
* @param {!myapp.Entity} entity An entity. 
* @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper. 
* @constructor 
* @extends {goog.ui.Component} 
*/ 
myapp.BottomPane = function(entity, opt_domHelper) { 
    goog.base(this, opt_domHelper); 
    this.setModel(entity); 
} 
goog.inherits(myapp.BottomPane, goog.ui.Component); 

然而,当我跑我的javascript,Chrome的控制台指出,Uncaught TypeError: Object #<Object> has no method 'setModel'。我设置了一个断点,并且意识到,实际上,我的myapp.BottomPane实例在原型链中缺少setModel方法。这是奇怪,因为该文件指出,所有组件都具有这个方法:http://closure-library.googlecode.com/svn/docs/class_goog_ui_Component.html

为什么我goog.ui.Component缺乏setModel方法?我知道goog.base(this, opt_domHelper);的调用正在工作,因为我的对象有一个DOM助手。

回答

2

我能够通过执行构造函数myapp.BottomPane而不使用new关键字来重现错误Object #<Object> has no method 'setModel'

var bottomPane = myapp.BottomPane({id: 'my_id'}); // Results in error. 

确保使用new来创建实例。

var bottomPane = new myapp.BottomPane({id: 'my_id'}); // Okay 
相关问题