I have this Demo which execution alert and it is work well:
below the code.
var Shape = function(){};
var TwoDShape = function(){};
Shape.prototype.name = 'shape';
Shape.prototype.toString = function(){return this.name;};
alert('there is alert');
when I add this line :extend(TwoDShape, Shape);
I can’t to execution alert as you can see Demo
after this I add lines:
var my = new TwoDShape();
alert(my.toString());
alert(TwoDShape.prototype.name);
alert(my.hasOwnProperty('name'));
to alert the name of the class shape or TwoDShape but I can’t successfull to display
the class.name why ?
First, you do not have function
extend()inside you code, so the code encounters error there and stopped running.So I fixed it using jQuery
$.extend(), or you can write theextend()yourself (see Jimmy’s answer).Secondly, if you want all Shape/TwoDShape instances have the class
nameto be accessible usingtoString(), you need to extend the prototype:TwoDShape.prototype = $.extend(TwoDShape.prototype, Shape.prototype);See the jsfiddle I created http://jsfiddle.net/4Bjjp/6/ on extending prototype