0

I have defined two prototypes each contain different function.

var sfSvgRender = function (element) {

    this.svgLink = "http://www.w3.org/2000/svg";
    this.svgObj = document.createElementNS(this.svgLink, "svg");
    this._rootId = $(element).attr("id");
    this.svgObj.setAttribute('id', this._rootId + '_svg');

};
sfSvgRender.prototype = new (function () {
    this.drawPath = function (options, element) {
        var path = document.createElementNS(this.svgLink, "path");
        $(path).attr(options);
        $(path).appendTo(element);

    },

})();


var sfAxisRender = function (axis) {
    this.currentAxis = axis;
};
sfAxisRender.prototye =new(function(){

    this.drawText=function (options, label, groupEle, svgObj) {
        var text = document.createElementNS(this.svgLink, "text");
        $(text).attr(options);
        $(text).html(label);
        $(text).appendTo(groupEle);
        $(groupEle).appendTo(svgObj);

    }

})();

when am creating the instance for both objects first object will work properly(i.e we can able to access the method of first prototype)

but can't able to access the method of second prototype.

this.svgRenderer = new sfSvgRender(this.element);

this.axisRender=new sfAxisRender(XAxis);

this.svgRenderer works properly. but axisRender doesn't work properly.

Cœur
  • 37,241
  • 25
  • 195
  • 267
SivaRajini
  • 7,225
  • 21
  • 81
  • 128
  • Do not [use `new` to create prototype objects](http://stackoverflow.com/q/10406552/1048572)! – Bergi Apr 17 '13 at 11:45
  • What exactly "does not work properly"? Do you get any errors? – Bergi Apr 17 '13 at 11:48
  • i cant able to access the method of drawText from sfAxisRender prototype.but i can able access all the methods of sfSVgRender prototype/object. – SivaRajini Apr 17 '13 at 11:52
  • i have removed "new" and tried again but doesn't get the method of drawText – SivaRajini Apr 17 '13 at 11:53
  • am not getting error message. above codes are in seperate script file called "render.js". this script will be loaded first . i can able to access the method of "sfSvgrender" but am trying to access the method "drawText" .it shows undefined. – SivaRajini Apr 17 '13 at 11:57

1 Answers1

1

You have missspelled prototype as prototye on sfAxisRender, that's why it doesn't inherit from the new prototype instance thing you tried to assign.

function sfSvgRender(element) {
    this.svgLink = "http://www.w3.org/2000/svg";
    this.svgObj = document.createElementNS(this.svgLink, "svg");
    this._rootId = $(element).attr("id");
    this.svgObj.setAttribute('id', this._rootId + '_svg');
}
sfSvgRender.prototype.drawPath = function (options, element) {
    var path = document.createElementNS(this.svgLink, "path");
    $(path).attr(options);
    $(path).appendTo(element);
};

function sfAxisRender(axis) {
    this.currentAxis = axis;
}
sfAxisRender.prototype.drawText = function (options, label, groupEle, svgObj) {
    var text = document.createElementNS(this.svgLink, "text");
    $(text).attr(options);
    $(text).html(label);
    $(text).appendTo(groupEle);
    $(groupEle).appendTo(svgObj);
};
Bergi
  • 630,263
  • 148
  • 957
  • 1,375