简体   繁体   English

javascript继承函数导致jquery错误

[英]javascript inheritance function causing jquery error

I made 2 functions that i want to use when creating javascript "class" inheritance. 我创建了2个在创建javascript“类”继承时要使用的函数。 I think its the first one thats causing some javascript errors, like $ is not defined for example. 我认为这是导致某些JavaScript错误的第一个问题,例如$ is not defined I think its just some errors that are stopping my custom jquery functions from running, thus complaining about the $ 我认为这只是一些错误,这些错误使我的自定义jquery函数停止运行,从而抱怨了$

Object.prototype.Inherits = function (parent) {
    if (arguments.length > 1) {
        parent.apply(this, Array.prototype.slice.call(arguments, 1));
    }
    else {
        parent.call(this);
    }
}

Function.prototype.Inherits = function (parent) {
    this.prototype = new parent();
    this.prototype.constructor = this;
}

I think the first function needs a remake. 我认为第一个功能需要重制。 Any suggestions? 有什么建议么? Thanks 谢谢

Don't modify the built-in prototypes. 不要修改内置的原型。 That's not the way. 不是那样的 Either: 要么:

  • embrace the prototypal inheritance model and Object.create() , 包含原型继承模型和Object.create()
  • use a non-invasive solution for your methods. 为您的方法使用非侵入性解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM