随笔分类 -  js

摘要://定义对象 var person={}; console.log(person); //为对象添加属性 person['name']='tim'; console.log(person); //为对象添加属性(属性为参数变量) var attrVar='like'; person[attrVar] 阅读全文
posted @ 2021-02-28 23:56 一首简单的歌 阅读(1946) 评论(0) 推荐(0)
摘要:js中的this容易产生误用,举例说明使用: 一 常规用法: var person = { name: 'tim', love: function () { console.log(this.name + ' like playing basketball'); } } person.love(); 阅读全文
posted @ 2021-02-22 23:02 一首简单的歌 阅读(68) 评论(0) 推荐(0)
摘要:var person = { name: 'tim', age: 40, profession: 'basketball' } console.log(Object.keys(person)); console.log(Object.values(person)); console.log(Obje 阅读全文
posted @ 2021-01-07 00:08 一首简单的歌 阅读(151) 评论(0) 推荐(0)
摘要:现象: 下例为一个js的foreach操作,看打印的结果,return是无法中断foreach处理的。 var testArray = [1, 2, 3, 4, 5]; testArray.forEach(element => { if (element == 3) { return; } cons 阅读全文
posted @ 2020-12-01 23:29 一首简单的歌 阅读(1585) 评论(0) 推荐(0)
摘要:一 Date中获取月份的范围是0-11,不是1-12 所以在使用时需要注意,如果需要通过Date拿到正确的月份,可以拿到month后进行+1操作。 var date=new Date(); console.log(date); console.log("当前月份:",date.getMonth()) 阅读全文
posted @ 2020-07-03 23:56 一首简单的歌 阅读(194) 评论(0) 推荐(0)
摘要:1、shim 原意:用垫片填。 javascript中:将一个新的API引入到一个旧的环境中,而且仅靠旧环境中已有的手段实现。比如:一些js库的新特性对旧浏览器的兼容支持。 阅读全文
posted @ 2018-12-05 11:46 一首简单的歌 阅读(409) 评论(0) 推荐(0)