I have a class setup as follows:
var oTest = new TEST();
function TEST() {
this.String = function(sString) {
this.Trim = function() {
}
}
}
I want to be able to call the Trim function as follows:
var sTrimmed = oTest.String(" something").Trim();
Is this the correct approach? Any help would be greatly appreciated as i have never done functions inside class functions before.
Add your methods to the
prototypeof the constructor function, and doreturn this;inString, to return the same object, which makes it chainable.live demo: http://jsfiddle.net/BcwgC/