I have a javascript function (using NodeJS but not particularly relevant here) like this:
var method = {};
method.create = function(){
console.log('Method was created')
}
method.create.function1 = function(){
console.log("This is method 2")
}
method.create.series = ['one', 'two', 'three'];
If I call method.create.function1() it correctly runs that function and console logs: This is method 2.
If I call method.create.series[0], I am returned: "one"
However, if I call:
var app = method.create();
app.function1() // returns undefined
I've tried:
var method = {};
method.create = function(){
console.log('Method was created')
this.function1 = function(){
console.log("This is method 2")
}
this.series = ['one', 'two', 'three'];
}
but this doesn't work at all. Anything I can do to be able to pass these methods along to a new variable?
method.create()returnsundefined.methodis a very misleading thing to call a variable that refers to an object rather than a function. It's also fairly unusual to assign functions as properties on function objects, although it can certainly be useful in some cases (KnockoutJS does it with observables, for instance, and of course all normal JavaScript functions have methods on them likecall,apply, ...).