diff --git a/.DS_Store b/.DS_Store index f5a2a2c..6e66fe0 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/ES6/proxy.js b/ES6/proxy.js index b402ec4..8c0f5d4 100644 --- a/ES6/proxy.js +++ b/ES6/proxy.js @@ -1,7 +1,36 @@ // @ts-nocheck -var proxy = new Proxy({}, { - get(target, propKey){ - return 35 - } -}) +// var proxy = new Proxy({}, { +// get(target, propKey){ +// return 35 +// } +// }) + +// var obj = { +// a: 1, +// b: 2 +// } +// const data = new Proxy(obj, { +// get(target, key, weizhi){ +// console.log(target, key, weizhi) +// return target[key] +// }, +// set(target,) +// }) + +var obj = new Proxy({}, { + get(target, key, obj) { + console.log(target) + console.log(key) + console.log(obj) + // return target[key] + return Reflect.get(target, key) + }, + set(target, key, val, obj) { + console.log(target) + console.log(key) + console.log(val) + console.log(obj) + target[key] = val + } +}) \ No newline at end of file diff --git "a/\346\211\213\345\206\231\344\270\200\344\270\252apply.js" "b/\346\211\213\345\206\231\344\270\200\344\270\252apply.js" new file mode 100644 index 0000000..d2ff99f --- /dev/null +++ "b/\346\211\213\345\206\231\344\270\200\344\270\252apply.js" @@ -0,0 +1,14 @@ +Function.prototype.myApply = function(context, arr) { + if(typeof this !== 'function') { + return 'err' + } + context = context || window + context.fn = this + let res + if(!arr) { + res = context.fn() + } + res = context.fn(...arr) //如果有返回值 + delete context.fn + return res +} \ No newline at end of file diff --git "a/\346\211\213\345\206\231\344\270\200\344\270\252bind.js" "b/\346\211\213\345\206\231\344\270\200\344\270\252bind.js" new file mode 100644 index 0000000..82dad3e --- /dev/null +++ "b/\346\211\213\345\206\231\344\270\200\344\270\252bind.js" @@ -0,0 +1,13 @@ +//简易版本 +// 返回一个函数 可以传入参数 +Function.prototype.myBind = function(context) { + var _this = this + var context = context || window + //取出bind的第二个到后面的参数 + var args = [...arguments].slice(1) + return function () { + return _this.apply(context, args.concat(...arguments)) + } +} +//如果有构造函数 + diff --git "a/\346\211\213\345\206\231\344\270\200\344\270\252call.js" "b/\346\211\213\345\206\231\344\270\200\344\270\252call.js" new file mode 100644 index 0000000..25135ed --- /dev/null +++ "b/\346\211\213\345\206\231\344\270\200\344\270\252call.js" @@ -0,0 +1,21 @@ +Function.prototype.mycall = function(context) { + if(typeof this !== 'function') { + return 'err' + } + context = context || window + context.fn = this + const arrs = [...arguments].slice(1) + const res = context.fn(...arrs) //如果有返回值 + delete context.fn + return res +} + +function ff(){ + console.log(this.name) + return 1 +} +const obj = { + name: 'mycall' +} + +ff.mycall(obj) \ No newline at end of file diff --git "a/\346\211\213\345\206\231\345\256\236\347\216\260new.js" "b/\346\211\213\345\206\231\345\256\236\347\216\260new.js" new file mode 100644 index 0000000..c3f6317 --- /dev/null +++ "b/\346\211\213\345\206\231\345\256\236\347\216\260new.js" @@ -0,0 +1,7 @@ +function copyNew(){ + const obj = {} + const Constructor = [...arguments][0] + obj.__proto__ = Constructor.prototype + const res = Constructor.apply(obj,[...arguments].slice(1)) + return typeof res === 'object' ? res : obj +} \ No newline at end of file diff --git "a/\346\267\261\345\205\245\347\263\273\345\210\227/\344\275\234\347\224\250\345\237\237.html" "b/\346\267\261\345\205\245\347\263\273\345\210\227/\344\275\234\347\224\250\345\237\237.html" index 9bbfb33..d92629f 100644 --- "a/\346\267\261\345\205\245\347\263\273\345\210\227/\344\275\234\347\224\250\345\237\237.html" +++ "b/\346\267\261\345\205\245\347\263\273\345\210\227/\344\275\234\347\224\250\345\237\237.html" @@ -30,6 +30,21 @@

相对的动态作用域,函数的作用域在函数调用的时候才决 前面我们已经说了,JavaScript采用的是静态作用域,所以这个例子的结果是 1。 */ + + /* + testVo:{ + arg:{ + 0:1, + len: 1 + }, + a: 10, + b: unde, + c: unde, => 10 + d: func, + e: unde, => func + } + + */ \ No newline at end of file diff --git "a/\346\267\261\345\205\245\347\263\273\345\210\227/\345\216\237\345\236\213\345\210\260\345\216\237\345\236\213\351\223\276.html" "b/\346\267\261\345\205\245\347\263\273\345\210\227/\345\216\237\345\236\213\345\210\260\345\216\237\345\236\213\351\223\276.html" new file mode 100644 index 0000000..e55d5eb --- /dev/null +++ "b/\346\267\261\345\205\245\347\263\273\345\210\227/\345\216\237\345\236\213\345\210\260\345\216\237\345\236\213\351\223\276.html" @@ -0,0 +1,33 @@ + + + + + + 从原型到原型链 + + + + + \ No newline at end of file diff --git "a/\346\267\261\345\205\245\347\263\273\345\210\227/\346\267\261\345\205\245\344\271\213\346\265\256\347\202\271\346\225\260\347\262\276\345\272\246.html" "b/\346\267\261\345\205\245\347\263\273\345\210\227/\346\267\261\345\205\245\344\271\213\346\265\256\347\202\271\346\225\260\347\262\276\345\272\246.html" new file mode 100644 index 0000000..69763a7 --- /dev/null +++ "b/\346\267\261\345\205\245\347\263\273\345\210\227/\346\267\261\345\205\245\344\271\213\346\265\256\347\202\271\346\225\260\347\262\276\345\272\246.html" @@ -0,0 +1,11 @@ + + + + + + Document + + + + + \ No newline at end of file