diff --git a/20191117/20171117.md b/20191117/20171117.md index f5df867..f416136 100644 --- a/20191117/20171117.md +++ b/20191117/20171117.md @@ -15,5 +15,4 @@ * 继承:类与类的关系,js是模拟类,本质基于原型对象 * 多态:同一个行为,对不同的对象产生不同效果 * Object Oriented Programming 面向对象程序设计 oop - * Application Programming Interface 应用程序接口 api - * \ No newline at end of file + * Application Programming Interface 应用程序接口 api \ No newline at end of file diff --git a/20191120/20191120.md b/20191120/20191120.md index 2a06989..bc3d841 100644 --- a/20191120/20191120.md +++ b/20191120/20191120.md @@ -6,6 +6,8 @@ js 高级 怎样用面向对象的思想去编程 ---- 抽象 +抽象 + 特指具体的某一个事物 ----- 对象 特征 ------- 属性 diff --git a/20191123/20191123.md b/20191123/20191123.md index d678a49..79a8f75 100644 --- a/20191123/20191123.md +++ b/20191123/20191123.md @@ -142,4 +142,6 @@ Array Date -Math \ No newline at end of file +Math + +内置对象中可以添加原型方法 \ No newline at end of file diff --git a/20191130/20191130.md b/20191130/20191130.md new file mode 100644 index 0000000..7ed27fb --- /dev/null +++ b/20191130/20191130.md @@ -0,0 +1,111 @@ +# 20191120 + + + +给内置对象String添加原型方法,相当于在改变String对象的源码 +```js +var str = new String('abcdef') +String.prototype.myReverse = () => { + var str = '' + for( var i = this.length -1 ; i >= 0; i--) { + str += this[i] + } + return str +} +console.log(str.myReverse) +``` + +给内置对象Array添加原型方法 +```js +Array.prototype.mySort = () => { + for(var i = 0; i < this.length; i++) { + for(var j = 0; j < this.length - i; j ++) { + if(this[j] > this[j+1]) { + var temp = this[j] + this[j] = this[j +1] + this[j+1] = temp + } + } + } + return this +} +var arr = new Array(1,2,3,4,5,6,7,8) +console.log(arr.mySort()) +``` + +将局部变量变成全局变量 + +```js +// 匿名函数自执行 +(function(){ + console.log('哈哈哈') +})(); +(function(){ + console.log('哈哈哈') +}()); + +// 开始 +(function(){ + var num = 100 +})(); +console.log(num) // 报错,不是undefined + +// 传参方式 +(function(win){ + var num = 100 + win.n = num +})(window); +console.log(n) // 打印100 +``` + +undefined的情况 + +已定义未赋值 + +对象没定义的属性 + +函数并没有创建返回值 + +全局不一定是window 还可能使global + +## 生成随机数 +```js +// 生成随机数 -> 创建一个随机数对象 ---- 属性无 / 方法 -> 生成随机数 +// 构造函数Random ---> 局部转全局 ---> 暴露给window ---> 实例化 ---> 调用方法 ---> 完成生成随机数 +(function (window) { + // 创建随机数对象 + function Random() { + + } + Random.prototype.getRandom = (min, max) => { + // 0~5整数 + return Math.floor(Math.random() * (max - min) + min) + } + window.Random = Random +}(window)); +var random = new Random() +var num = random.getRandom(0, 5) +console.log(num) +``` + +js获取元素的方法 + +通过ID获取(getElementById) + +通过name属性(getElementsByName) + +通过标签名(getElementsByTagName) + +通过类名(getElementsByClassName) + +通过选择器获取一个元素(querySelector) + +通过选择器获取一组元素(querySelectorAll) + +获取html的方法(document.documentElement) + +document.documentElement是专门获取html这个标签的 + +获取body的方法(document.body) + +document.body是专门获取body这个标签的 \ No newline at end of file diff --git a/20191130/retroSnaker.html b/20191130/retroSnaker.html new file mode 100644 index 0000000..c5f3253 --- /dev/null +++ b/20191130/retroSnaker.html @@ -0,0 +1,92 @@ + + + +
+ + + +