Written 1
/ * * * Object method, self-executing functions, closures * / const buildTask = (() => { var Queue1 = []; return { Push (ITEM1) { queue1.push (ITEM1); the console.log (Queue1) ; } } }) (); const RES1 = buildTask.push (. 1 ); the console.log (RES1);
Writing 2
/ * * * Self-executing functions, closures * / const buildTask2 = (() => { var Queue2 = []; return (ITEM2) => { queue2.push (ITEM2); the console.log (Queue2); } } ) (); const RES2 = buildTask2 (. 1 ); the console.log (RES2);
Written 3
** * 类,构造函数 */ class TestTask { constructor() { this.queue3 = []; } buildTask3(item3) { return () => { this.queue3.push(item3); console.log(this.queue3); } } } const res3 = new TestTask; console.log(res3.buildTask3(1)());