Comments (2)
嗯,这是一个继承关系。
你说的对,应该再加一句 init.prototype.constructor = init;
constructor一般是在重写prototype之后重新赋值的,以保证原有构造函数不被改变。
但constructor本身没有太大的作用,这是因为:
函数A被定义时,JS引擎会给A添加一个prototype, 然后再给prototype添加一个constructor属性,并让其指向A的引用。这样做的目的是,当函数A被作为构造函数用来创建对象时,new出来的实例对象obj 就保留了对A的引用,这样,obj对象就被标记为是“A”类型,使得创建的对象更加规范,有名有姓,可追溯。
from jdate.
多谢多谢…真的是受益匪浅
from jdate.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jdate.