我在这里读了一篇文章:
http://javascriptweblog.wordpress.com/2010/03/16/five-ways-to-create-objects/
它讲述了五种创建对象的方法。但我的问题是他的方式之一(3)是:
myApp.Notepad = function(defaultFont) {
var that = {};
that.writeable = true;
that.font = defaultFont;
that.setFont = function(theFont) {
that.font = theFont;
}
return that;
}
myApp.notepad1 = myApp.Notepad('helvetica');
根据作者的说法,我们可以在需要多个实例时使用它,我们可以使用从 3(以上)到 5 的任何模式。
但据我所知,我们确实需要使用this
反映新创建实例并仅引用该实例的关键字。然而在上面,作者使用that
了 object 而不是上面this
也没有new
使用关键字。它将如何应用于多个对象实例?它本质上与使用相同this
吗?