var Person = function(){};
function klass() {
initialize = function(name) {
// Protected variables
var _myProtectedMember = 'just a test';
this.getProtectedMember = function() {
return _myProtectedMember;
}
this.name = name;
return this;
};
say = function (message) {
return this.name + ': ' + message + this.getProtectedMember();
// how to use "return this" in here,in order to mark the code no error.
};
//console.log(this);
return {
constructor:klass,
initialize : initialize,
say: say
}
//return this;
}
Person.prototype = new klass();
//console.log(Person.prototype);
new Person().initialize("I :").say("you ").say(" & he");
如何在「say」中使用「return this」,以便標記代碼沒有錯誤。Javascript「return this」符合「return」?
我想知道如何在已經返回alrealy的函數中「連鎖調用」?
你的功能可以返回響應消息或對象本身以允許鏈接。它不能同時返回。 – Simon 2012-03-02 10:57:08