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 of container();.
  • move new container(); line after prototype additions.
  • call this._open(); instead of alert(this._open); execute function.

so code should this:

function container() {     this._open(); }    container.prototype._open = function() {     alert('open'); } new container(); 

hope helps.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -