var Ob = function(){ } Ob.prototype.add = function(){ inc() } Ob.prototype.inc = function(){ alert(' Inc called '); } window.onload = function(){ var o = new Ob(); o.add(); }
I would like to call something like this,how can i call, ofcourse i put inc as inner function to add I can do that but without having the inner function. how do i do that ?
The JavaScript call() Method It can be used to invoke (call) a method with an owner object as an argument (parameter). With call() , an object can use a method belonging to another object.
1. 13. -1: prototype is a property of constructor functions, not instances, ie your code is wrong!
It's easy:
Ob.prototype.add = function(){ this.inc() } Ob.prototype.inc = function(){ alert(' Inc called '); }
When you create the instance of Ob
properties from prototype are copied to the object. If you want to access the methods of instance from within its another method you could use this
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With