I feel a bit dump but there is something I don\’t understand (or even know if it\’s possible) about prototyping in JavaScript.
I\’d like to use a method while I\’m creating the prototype of my pseudo-class :
var Class = function() {}
Class.prototype = {
a: function() {
return \'ok\'
}
, z: Class.prototype.a() // I tried with `this`/`constructor`/etc.
} // TypeError: Object [object Object] has no method \'a\' the rest isn\'t evaluated
var test = new Class()
test.z
I know I can do it this way but I\’d like to know if I can still but all my method/properties in the Class.prototype declaration :
var Class = function() {}
Class.prototype.a = function() {
return \'ok\'
}
Class.prototype.z = Class.prototype.a()
var test = new Class()
test.z // \"ok\"
Thanks.





Rating:
The post javascript – Reference of a method while creating the prototype appeared first on Javascript ASK.
via Javascript ASK http://javascriptask.phpfogapp.com/javascript-reference-of-a-method-while-creating-the-prototype.html
No comments:
Post a Comment