I was reading this article, and I took the example and made some very small modification
function Parent( p1, p2 ) {
console.log('run here');
var prop1 = p1; // private property
this.prop2 = p2; // public property
// private method
function meth1() { return prop1; }
// public methods
this.meth2 = function(){ return this.prop2; };
this.meth6 = function(){ return meth1(); };
}
Parent.prototype.hello=function(){console.log('hi '+this.prop2);};
function Child( p1, p2, p3, p4 ) {
Parent.apply( this, arguments ); // initialize Parent's members
this.prop3 = p3;
this.meth3 = function(){ return this.prop3; }; // override
var prop4 = p4;
this.meth4 = function(){ return prop4; };
}
Child.prototype = new Parent(); // set up inheritance relation
// console.log(Child.prototype)
var cc = new Child( "one", "two", "three", "four" );
console.log(cc)
var result1 = cc.meth6(); // parent property via child
var result2 = cc.meth2(); // parent method via child
var result3 = cc.meth3(); // child method overrides parent method
var result4 = cc.hello();
console.log(result1,result2,result3,result4);
The problem is even cc.hello method seems like exist, but when I call it, the console return undefined, can someone please explain why? thanks
hellomethod doesn't return anything, thusundefined. Not sure what you expect...