javascript - access prototype function from this -
i trying fix javascript uses functions , prototype functions. reason prototype function always undefined when try access , can't figure out why.
here simple example of i'm trying do. basically, want reference _open prototype within original container function declaration using this.
container(); function container() { alert(this._open); } container.prototype._open = function() { alert("hey"); } you can see in fiddle alerts "undefined." this question , this question both show examples of people doing this. why keep getting undefined?
three things:
- use
new container();instead ofcontainer();. - move
new container();line afterprototypeadditions. - call
this._open();instead ofalert(this._open);execute function.
so code should this:
function container() { this._open(); } container.prototype._open = function() { alert('open'); } new container(); hope helps.
Comments
Post a Comment