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