diff --git "a/26\350\260\242\351\207\221\351\207\221/\344\275\234\344\270\232/11.7\347\273\247\346\211\277\344\275\234\344\270\232.html" "b/26\350\260\242\351\207\221\351\207\221/\344\275\234\344\270\232/11.7\347\273\247\346\211\277\344\275\234\344\270\232.html" new file mode 100644 index 0000000000000000000000000000000000000000..213714f5677e65c44eab7678f2037f1f2fc7a447 --- /dev/null +++ "b/26\350\260\242\351\207\221\351\207\221/\344\275\234\344\270\232/11.7\347\273\247\346\211\277\344\275\234\344\270\232.html" @@ -0,0 +1,25 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git "a/26\350\260\242\351\207\221\351\207\221/\347\254\224\350\256\260/11.7\347\273\247\346\211\277\347\254\224\350\256\260.md" "b/26\350\260\242\351\207\221\351\207\221/\347\254\224\350\256\260/11.7\347\273\247\346\211\277\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..63c424c51f6fb589b1ef0cbcb29348671dce009d --- /dev/null +++ "b/26\350\260\242\351\207\221\351\207\221/\347\254\224\350\256\260/11.7\347\273\247\346\211\277\347\254\224\350\256\260.md" @@ -0,0 +1,32 @@ +| ## 圣杯模式(全): | | | +| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | +| | [2](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_2) | | +| | [3](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_3) | ***\*优化:\**** | +| | [4](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_4) | | +| | [5](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_5) | - 我们可以将它封装为一个方法,因为每次继承都会创建一个新的Temp中间函数,造成了资源浪费。优化代码如下 | +| | [6](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_6) | | +| | [7](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_7) | ```javascript | +| | [8](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_8) | **var** inherit = (**function** () { | +| | [9](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_9) | **var** Temp = **function**() {} | +| | [10](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_10) | **return** **function** (Target, Origin) { //target继承自origin | +| | [11](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_11) | Temp.prototype = Origin.prototype | +| | [12](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_12) | Target.prototype = **new** Temp() | +| | [13](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_13) | Target.prototype.**constructor** = Target //为了让Target原型的constructor指回Target | +| | [14](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_14) | Target.prototype.uber = Origin.prototype //找到自己的超类 | +| | [15](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_15) | } | +| | [16](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_16) | })() | +| | [17](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_17) | ``` | +| | [18](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_18) | | +| | [19](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_19) | - 由于es6有了Object.create()方法,可以改变函数的隐式原型(_**proto**_),也可以不用中间函数 | +| | [20](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_20) | | +| | [21](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_21) | ```javascript | +| | [22](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_22) | **function** inherit(Target, Origin) { | +| | [23](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_23) | Target.prototype = Object.create(Origin.prototype) | +| | [24](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_24) | Target.prototype.**constructor** = Target | +| | [25](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_25) | Target.prototype.uber = Origin.prototype | +| | [26](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_26) | } | +| | [27](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_27) | ``` | +| | [28](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_28) | | +| | [29](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_29) | this | +| | [30](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_30) | | +| | [31](https://gitee.com/level-21-software-class-4/java-script/pulls/336/files#f7650314366b53c85cc442a4f967ebe5fa765b37_0_31) | 如果this有自己的属性,那么会覆盖掉原型上已有的属性。****(开发惯例:所有方法写到原型,部分属性写到this)一般来说属性是配置项,需要你主动传参去配置。但是一般来说某个插件的方法功能几乎是 | \ No newline at end of file