Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单个脚本文件中的两个原型引发了这个问题_Javascript_Jquery - Fatal编程技术网

Javascript 单个脚本文件中的两个原型引发了这个问题

Javascript 单个脚本文件中的两个原型引发了这个问题,javascript,jquery,Javascript,Jquery,我定义了两个原型,每个原型包含不同的函数 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'

我定义了两个原型,每个原型包含不同的函数

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);

    }

})();
当我为两个对象创建实例时,第一个对象将正常工作(即我们可以访问第一个原型的方法)

但无法访问第二个原型的方法

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

this.axisRender=new sfAxisRender(XAxis);

这个.svgrender工作正常。但是axisRender无法正常工作。

您在
sfAxisRender
上将
prototype
拼写为
prototye
,这就是为什么它不会继承您尝试分配的新原型实例

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);
};

不要!究竟什么是“不能正常工作”?您是否收到任何错误?我无法从sfAxisRender prototype访问drawText的方法。但我可以访问SFSgrender prototype/object的所有方法。我已删除“new”并重试,但未获得drawText的方法。我未收到错误消息。上述代码位于名为“render.js”的单独脚本文件中。将首先加载此脚本。我可以访问“sfSvgrender”方法,但我正在尝试访问“drawText”方法。它显示未定义。