js 원형 체인 노트

3381 단어




Title



16 , 16 。


new



1. (prototype):
function ,
。 ,
。 。
2. , 。
3. --> __proto__ ( )
4. -->constructor ( )


Object.prototype Object.create(null) Object.prototype
Object.create( , Person.prototype)

call/apply:
: this 。
: 。

call:
apply: arguments



1. -->

2. (call/apply)


3. ( .prototype = .prototype)

4.



<br><br><br> // Person.prototype <br> // Person.prototype = {} var person = new Person(); <br><br> Person.prototype = {<br> proto : 123,<br> };<br> function Person(name , age , sax) {<br> this.name = name;<br> this.age = age;<br> this.sax = sax;<br> }<br> var person = new Person(' ', 20 , 'male');<br><br> // <br> function Person(name, age, sex) {<br> this.name = name;<br> this.age = age;<br> this.sex = sex;<br> }<br> function Student(name, age, sex, tel, grade) {<br> Person.call(this, name, age, sex);<br> this.tel = tel;<br> this.grade = grade;<br> }<br> var student = new Student('xie', 20, 'male', 111, 2019);<br><br><br><br>// <br> // 1. <br> Father.prototype.lastname = 'deng';<br> function Father() {}<br> function Son() {this.sex = 'hehe';}<br> function inherit(Target, Origin) {<br> function F() {}<br> F.prototype = Origin.prototype;<br> Target.prototype = new F();<br> Target.prototype.constructor = Target;<br> Target.prototype.uber = Origin.prototype; // <br> }<br> inherit(Son, Father);<br> var son = new Son();<br> var father = new Father();<br> <br> //2. TUI3 <br><br> Father.prototype.lastname = 'deng';<br> function Father() {}<br> function Son() {this.sex = 'hehe';}<br> var inherit = (function () {<br> var F = function () {};<br> return function (Target, Origin) {<br> F.prototype = Origin.prototype;<br> Target.prototype = new F();<br> Target.prototype.constructor = Target;<br> Target.prototype.uber = Origin.prototype;<br> }<br> }());<br> inherit(Son, Father);<br> var son = new Son();<br> var father = new Father();<br>



좋은 웹페이지 즐겨찾기