Giter Site home page Giter Site logo

Comments (2)

git-onepixel avatar git-onepixel commented on June 28, 2024

嗯,这是一个继承关系。
你说的对,应该再加一句 init.prototype.constructor = init;
constructor一般是在重写prototype之后重新赋值的,以保证原有构造函数不被改变。

但constructor本身没有太大的作用,这是因为:

函数A被定义时,JS引擎会给A添加一个prototype, 然后再给prototype添加一个constructor属性,并让其指向A的引用。这样做的目的是,当函数A被作为构造函数用来创建对象时,new出来的实例对象obj 就保留了对A的引用,这样,obj对象就被标记为是“A”类型,使得创建的对象更加规范,有名有姓,可追溯。

from jdate.

zjhch123 avatar zjhch123 commented on June 28, 2024

多谢多谢…真的是受益匪浅

from jdate.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.