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");
how to use “return this” in “say”,in order to mark the code no error.
i want to know that how to ‘Chain call’ in the function which has return alrealy?
You need return a class instance to chain call. I would suggest you create a base class for all your objects that is able to store the outputs of the class, and will return it in the “toString” or similar function, maybe “output”.
Your code then becomes: