javascript - Can I create a function that's a property of a function in an object? -
i access function within object this
function myobject() { this.create = function(array) { var myarray = array; this.arraylength = function(){return myarray.length;} // else here... } } var foo = new myobject(); foo.create(value); console.log(foo.create.arraylength();); i undefined response .create.length(), possible way?
when call .create() method foo.create(), within .create() this foo. line:
this.arraylength = function(){return myarray.length;} creates method arraylength() on foo. use:
console.log(foo.arraylength()); if reason want arraylength() method of create this:
this.create.arraylength = function(){return myarray.length;} and use original:
console.log(foo.create.arraylength()); (minus semicolon before closing bracket).
but while latter version "works" seems kind of strange way go.
Comments
Post a Comment