+ 1
Methods of my function... How?
I have a function. And I most create method of this function. But this function don't have a name. function getSomeThink() { // code return function () { // code } } var working = getSomeThink(); working.go(); How to create method 'go' of 'working'? Thank.
2 Respuestas
+ 8
or if following your existing code
function getSomeThink() {
// code
return function () {
// code
alert(42);
}
}
var working= getSomeThink();
working();
the last line will call the function which returned from getSomeThink()
but this way you cannot call it "go"
+ 7
follow this pattern
function foo(){
this.goo = function(){
alert(42);
}
}
var f = new foo();
f.goo();