diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\344\271\235\345\221\250/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\344\271\235\345\221\250/.keep" new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\344\271\235\345\221\250/W19_L1.txt" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\344\271\235\345\221\250/W19_L1.txt" new file mode 100644 index 0000000000000000000000000000000000000000..55e79a991b08ccbe8ee48a9eb3003e379b0d06b0 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\344\271\235\345\221\250/W19_L1.txt" @@ -0,0 +1,80 @@ +const MAX_NUMBER = 10; +let j = 0; +let my_obj = {a:1, b:2, c:3}; +let my_obj_iter = [1, 2, 3, 4, 5]; +let myArray = [1, 3, 5, 7]; + + +/* +for (let i=0; i<20; i++){ + console.log(i); +} +*/ + +/* +while (j < MAX_NUMBER){ + console.log(j); + j++; +} +*/ + +/* +do { + console.log(j); + j++; +} while (j < MAX_NUMBER) +*/ + +for (let e in my_obj) { + console.log(e, my_obj[e]); +} + +for (let e of my_obj_iter){ + console.log(e); +} + +myArray.forEach (function (e) { + console.log(e**2); +}) + +for(let i=-2; i<20; i++){ + if (i < 0){ + console.log("负数不判断", i); + }else if(i%2===0){ + console.log("偶数", i); + }else{ + console.log("奇数", i); + } +} + +function foo(e) { + switch (e) { + case 'a': + console.log("arg is a"); + break; + case 'b': + console.log("arg is b"); + break; + default: + console.log("default arg is c"); + } +} + +foo('e'); + +function foo2(){ + try{ + throw TypeError('test'); + //throw {'a':1}; + }catch (e){ + if (e instanceof TypeError){ + console.log("TypeError"); + }else{ + console.log('Error', e); + } + }finally{ + console.log('Done!'); + } +} + +foo2(); diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\344\271\235\345\221\250/W19_L2.txt" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\344\271\235\345\221\250/W19_L2.txt" new file mode 100644 index 0000000000000000000000000000000000000000..00499ed8dc4d0c927bb843d8a0034688cfddab1e --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\344\271\235\345\221\250/W19_L2.txt" @@ -0,0 +1,80 @@ +class Rectangle { + constructor(width, height){ + this.width = width; + this.height = height; + this.name = "rectangle"; + this._author = "chaos"; + } + + static staticMethod(){ + console.log("this is static method"); + } + + getArea(){ + return this.width * this.height; + } + + get area(){ + return this.getArea(); + } + + set author(name){ + this._author = name; + } +} + +let square = new Rectangle(2, 2); +console.log(square.area); +console.log(square._author); +Rectangle.staticMethod(); +square.author = 'john'; +console.log(square._author); + +class Square extends Rectangle { + #new_name + constructor(a){ + super(a, a); + this.#new_name = "square"; + } + + get new_name(){ + return this.#getnewName(); + } + + #getnewName() { + return this.#new_name; + } +} + +function Rectangle2(height, width){ + this.name = 'rectangle'; + this.width = width; + this.height = height; + + this.getArea = function (){ + return this.height * this.width; + } +} + +let rec = new Rectangle2(2, 3); +console.log(rec.getArea()); + +//call +function Square2(a){ + Rectangle.call(this, a, a); + this.name = 'square'; +} +//apply +function Square3(a){ + Rectangle.apply(this, [a, a]); + this.name = 'square'; +} +//proto +function Square4(a){ + this.height = a; + this.width = a; + this.name = 'square' +} +Square4.prototype = new Rectangle(); +let square4 = new Square4(10); +console.log(square4.getArea()); \ No newline at end of file diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\344\271\235\345\221\250/W19_L3.txt" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\344\271\235\345\221\250/W19_L3.txt" new file mode 100644 index 0000000000000000000000000000000000000000..b44af4ba498fa95b9992ef43320e848311779288 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/2\347\217\255/2\347\217\255_chaos/\347\254\254\345\215\201\344\271\235\345\221\250/W19_L3.txt" @@ -0,0 +1,56 @@ +//callback +document.addEventListener("click", function(e){console.log(e)}) + +//Promise +/* +A Promise is in one of these states: + +pending: initial state, neither fulfilled nor rejected. +fulfilled: meaning that the operation was completed successfully. +rejected: meaning that the operation failed. +*/ +const promise1 = new Promise((resolve, reject) => { + setTimeout(() => { + resolve('foo'); + }, 300); +}); + +promise1.then((value) => { + console.log(value); + // expected output: "foo" +}); + +console.log(promise1); +// expected output: [object Promise] + +function myAsyncFunction(url) { + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.open("GET", url); + xhr.onload = () => resolve(xhr.responseText); + xhr.onerror = () => reject(xhr.statusText); + xhr.send(); + }).then(result => {console.log("SUCCESS", result)}) + .catch(error => {console.log("FAILURE", error)}) +} + + +// async/await +function xhrRequest(url){ + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.open('GET', url); + xhr.onload = function(){resolve(xhr.responseText)}; + xhr.onerror = () => reject(xhr.status); + xhr.send(); + }) +} + +async function requestBaidu(url){ + try{ + let result = await xhrRequest(url); + console.log("DONE", result); + }catch (e) { + console.log("ERROR", e); + } +}