diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/.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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_1/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_1/.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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_1/week19_1pra.js" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_1/week19_1pra.js" new file mode 100644 index 0000000000000000000000000000000000000000..783bc667172c419f7a6e9a66d8bb09c7d5d70a37 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_1/week19_1pra.js" @@ -0,0 +1,96 @@ +//循环语句: for循环,while循环 +for(let i=0; i<20; i++){ + console.log(i) +} + +const MAX_TIMES =20; +let cur = 0 +while (cur < MAX_TIMES){ + cur++; + console.log(cur) +} +// for in 遍历对象的属性 +let myObj = {a: 1, b: 2, c: 3, d: 4} +for (let e in myObj){ + console.log(e, myObj[e]); +} +//for of 遍历可迭代对象的元素 +let myArray = [1, 2, 3, 4, 5] +for (let e of myArray){ + console.log(e) +} +// forEach 常用 +let myArray = [1, 2, 3, 4, 5] +myArray.forEach(function (e : number)){ + console.log(e * e); +}) +// do while +const MAX_TIMES = 20; +let cur = 0 + +do { + cur ++; + console.log(cur); +}while (cur < MAX_TIMES) + + +//条件语句 +for(let i=0; i,100; i++) { + if (i % 2 === 0){ + consol.log("偶数", i) + } else if (i < 0) { + console.log("负数不判断") + }else{ + console.log("奇数", i) + } +} +/*逻辑运算符 +== +=== 等于 +! 逻辑取反 +&& and + || or +*/ +//选择语句 +function foo(arg){ + switch (arg){ + case 'a': + console.log(arg, 1); + break; + case 'b': + console.log(arg, 2); + break; + case 'c': + consloe.log(arg, 3); + break; + default: + console.log('default') + } +} +foo('e') +//异常处理 +function foo(){ + try{ + throw TypeError('test'); + }catch (e){ + console.log('Error' e); + }finally { + console.log('Done') + } +} + + +function foo(){ + try{ + throw TypeError('test'); + }catch (e) { + if (e instanceof TypeError) { + console.log("TypeError") + } else { + console.log('Error', e); + } + }finally{ + console.log('Done!') + } +} +//抛出异常 diff --git "a/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_2/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_2/.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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_2/week19_2pra.js" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_2/week19_2pra.js" new file mode 100644 index 0000000000000000000000000000000000000000..619d8c1f41e7d93f994dcd7c85aa2d96d1cf8869 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_2/week19_2pra.js" @@ -0,0 +1,165 @@ +/* +第十九周第二节课练习 +一,对象和类 +二,构造函数和this +三,原型式继承 + */ +// 对象和类 +class Rectangle { + constructor(height, width) { + this.name = 'rectangle'; + this.height = height; + this.width = width; + } + + +} + +let rectangle = new Rectangle(2,5); +console.log(rectangle) + +//实例方法 +class Rectangle { + constructor(height, width) { + this.name = 'rectangle'; + this.height = height; + this.width = width; + } + + getArea(){ + return this.height * this.width; + } +} + +//静态方法 +class Rectangle { + constructor(height, width) { + this.name = 'rectangle'; + this.height = height; + this.width = width; + } + + getArea(){ + return this.height * this.width; + } + + static staticMethod(){ + console.log("calling static method") + } +} +// getter 和 setter +class Rectangle { + constructor(height, width) { + this.name = 'rectangle'; + this.height = height; + this.width = width; + } + + getArea(){ + return this.height * this.width; + } + + static staticMethod(){ + console.log("calling static method") + } + get area(){ + return this.getArea() + } + + set area(value){ + this._value = value + } +} + +//类继承 +class Rectangle { + constructor(height, width) { + this.name = 'rectangle'; + this.height = height; + this.width = width; + } + + getArea(){ + return this.height * this.width; + } + + static staticMethod(){ + console.log("calling static method") + } + get area(){ + return this.getArea() + } + + set area(value){ + this._value = value + } +} + +class Square extends Rectangle { + constructor(a) { + super(a, a); + this.name = 'sqaure' + } +} + +let suqare = new Square(10) +console.log(suqare.area) + + +//构造函数和this +function Rectangle(height, width){ + this.name = 'rectangle'; + this.width = width; + this.height = height; + + this.getArea = function (){ + return this.height * this.width + } +} + +let rectangle = new Rectangle(10, 2) +console.log(rectangle.getArea()) + +//通过call方法继承 +function Rectangle(height, width){ + this.name = 'rectangle'; + this.width = width; + this.height = height; + + this.getArea = function (){ + return this.height * this.width + } +} + +function Square(a){ + Rectangle.call(this, a, a); + this.name = 'square' +} + +let square = new Square(10); +console.log(square.getArea()) +//原型链式继承 +let square = new Square(10); +console.log(square.__proto__.__proto__) + + +//原型链式继承 +function Rectangle(height, width){ + this.name = 'rectangle'; + this.width = width; + this.height = height; + + this.getArea = function (){ + return this.height * this.width + } +} + +function Square(a){ + this.height = a; + this.width = a; + this.name = 'aquare' +} + +Square.prototype = new Rectangle() +square = new Square(10) +console.log(square.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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_3/.keep" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_3/.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/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_3/week19_3pra.js" "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_3/week19_3pra.js" new file mode 100644 index 0000000000000000000000000000000000000000..f31b4146b503c8f28088549178db926cfcb146d7 --- /dev/null +++ "b/\347\254\254\344\272\214\346\234\237\350\256\255\347\273\203\350\220\245/3\347\217\255/3\347\217\255_\351\231\266\345\206\266/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232/3\347\217\255_\351\231\266\345\206\266_\347\254\254\345\215\201\344\271\235\345\221\250\344\275\234\344\270\232_3/week19_3pra.js" @@ -0,0 +1,76 @@ +/* +* 异步JS callback promise async/await +* +* */ +//声明一个promise对象 +let promiseObj = new Promise( (resolve, reject) => { + + setTimeout(() => { + resolve("success"); + reject("failed"); + }, 3*1000) +}).then(result => {console.log("result => ", result)}) + +console.log(promiseObj) + +//声明一个xhr请求 +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() + }).then(result=>{console.log("SUCCESS", result)}) + .catch(error=>{console.log("FAILURE", error)}) +} + +//链式调用 +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() + }).then(result=>{console.log("SUCCESS", result); return result}) + .then(result=>{console.log("SUCCES 2", 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() + }).then(result=>{console.log("SUCESS", result); return result}) + .catch(error=>{console.log("FAILURE", error); throw TypeError}) +} + +async function requestBaidu(url){ + let result = await xhrRequest(url); + console.log("DONE!", result) +} + +//异常处理 +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("FAILURE",e) + } +} \ No newline at end of file