diff --git "a/39\351\231\206\345\273\272\351\224\213/2022-11-4\345\216\237\345\236\213\351\223\276\344\270\216\347\273\247\346\211\277/2022_11_04\345\216\237\345\236\213\351\223\276&\347\273\247\346\211\277.html" "b/39\351\231\206\345\273\272\351\224\213/2022-11-4\345\216\237\345\236\213\351\223\276\344\270\216\347\273\247\346\211\277/2022_11_04\345\216\237\345\236\213\351\223\276&\347\273\247\346\211\277.html" new file mode 100644 index 0000000000000000000000000000000000000000..e7821087d6b691b11bef1f89a89d87088e3a71da --- /dev/null +++ "b/39\351\231\206\345\273\272\351\224\213/2022-11-4\345\216\237\345\236\213\351\223\276\344\270\216\347\273\247\346\211\277/2022_11_04\345\216\237\345\236\213\351\223\276&\347\273\247\346\211\277.html" @@ -0,0 +1,165 @@ + + + + + + + + Document + + + + + + + \ No newline at end of file diff --git "a/39\351\231\206\345\273\272\351\224\213/2022-11-4\345\216\237\345\236\213\351\223\276\344\270\216\347\273\247\346\211\277/\344\275\234\344\270\232.html" "b/39\351\231\206\345\273\272\351\224\213/2022-11-4\345\216\237\345\236\213\351\223\276\344\270\216\347\273\247\346\211\277/\344\275\234\344\270\232.html" new file mode 100644 index 0000000000000000000000000000000000000000..60ea87911688343f039ce283a464145d755a8405 --- /dev/null +++ "b/39\351\231\206\345\273\272\351\224\213/2022-11-4\345\216\237\345\236\213\351\223\276\344\270\216\347\273\247\346\211\277/\344\275\234\344\270\232.html" @@ -0,0 +1,111 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git "a/39\351\231\206\345\273\272\351\224\213/2022-11-4\345\216\237\345\236\213\351\223\276\344\270\216\347\273\247\346\211\277/\347\254\224\350\256\260.md" "b/39\351\231\206\345\273\272\351\224\213/2022-11-4\345\216\237\345\236\213\351\223\276\344\270\216\347\273\247\346\211\277/\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..e9370493415797ea6c5ffdcd17ad5eeffeeaaa52 --- /dev/null +++ "b/39\351\231\206\345\273\272\351\224\213/2022-11-4\345\216\237\345\236\213\351\223\276\344\270\216\347\273\247\346\211\277/\347\254\224\350\256\260.md" @@ -0,0 +1,99 @@ +构造函数的属性优先于原型上的属性 + 原型重写 + 例: + function Fun(){}; + function Fun1(){}; + Fun.prototype.name = '2' + var fun = new Fun(); + Fun1.prototype = fun + var fun1 = new Fun1(); + Fun1.prototype.name = '3' + console.log(fun.name); + console.log(fun1.name); + + 原型链 继承:继承父类的属性和方法 + 原型链继承:会将父级上的所有属性和方法统统继承过来:过多地继承没用的属性 + function Grand() {} //爷爷 + function Parent() {} //爸爸 + function Child(){}//孩子 + Grand.prototype.tskill = '拉二胡'; + var grand = new Grand(); + Parent.prototype = grand; + var parent = new Parent(); + //原型重写 + Parent.prototype.tskill = '弹琴'; + console.log(grand.tskill); + console.log(parent.tskill); + + 2.构造函数继承:使用call + function Parent(name,age){ + this.name = name; //child.name + this.age = age; //child.age + } + + function Child(name,age,sex){ + //call + Parent.call(this,name,age); + this.sex = sex; + } + var child = new Child('张三',18,'male'); + console.log(child.name); + + 3.共享原型继承 + function Grand(){} + Grand.prototype.name = '爷爷'; + + function Parent(){ + } + Parent.prototype.name = '爹'; + Parent.prototype.age = 40; + + function Child(){ + } + //名字是默认的 + function inherit(Target,Origin){ + Target.prototype = Origin.prototype; + } + + inherit(Child,Parent); + Child.prototype.age = 100; //共享 + var child = new Child(); + console.log(child.age); + + + + 4.圣杯(永恒)模式 + function Parent() { + } + Parent.prototype.name = '爹'; + Parent.prototype.age = 40; + + function Child() { + } + + function inherit(Target, Origin) { + function F(){} //临时构造函数 + F.prototype = Origin.prototype; + // var f = new F();//实例化:复制一份 + // Target.prototype = f; //独立的f,里面有父类所有的属性和方法 + Target.prototype = new F(); + //归位 + //构造器归位 + Target.prototype.constructor = Target; + //超类 + Target.prototype.uber = Origin; + + } + + //Parent.prototype.constructor + + + inherit(Child, Parent); + var child = new Child(); + console.log(child.__proto__.uber); + Child.prototype.name = '张三'; + // console.log(child.name); + // console.log(Child.prototype.constructor); + // var parent = new Parent(); + // console.log(); + // console.log(parent.name); \ No newline at end of file