GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — data-structure-and-algorithm-in-JavaScript/call&apply.html at main · shaw-555/data-structure-and-algorithm-in-JavaScript Expand file tree/ Copy pathcall&apply.htmlMore file actions 49 lines (36 loc) · 1.08 KB / Copy pathcall&apply.htmlFile metadata and controls49 lines (36 loc) · 1.08 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> </body> <script type="text/javascript"> Function.prototype.myApply = function(content= window, ...args){ content = content ? Object(content): window; let func = this; let fn = Symbol("fn"); content[fn] = func; let res = content[fn](...args); delete content.fn; return res; } Function.prototype.myCall = function(content,args){ // 如果有content,令其为对象;否则,令之为window content = content ? Object(content): window; // 谨记,this为函数 let func = this; // 创造独一无二的索引 let fn = Symbol("fn"); content.fn = func; // 先返回结果,结果为指向另一个变量,所以不会受到后面 delete content.fn 而影响 let res = content.fn(args); // 删掉避免产生命名冲突 delete content.fn; return res; } console.log(Object.prototype.toString.myCall([])); </script> </html> |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |