代码改变世界

随笔档案-2017年05月

js面试题,关于变量提升,作用域,全局变量

2017-05-10 00:13 by 陶俊龙, 515 阅读, 收藏,
摘要: /**********seperate line************/ var a = 10; function test() { a = 100; console.log(a); console.log(this.a); var a; console.log(a); } test(); VM3 阅读全文

js中实现事件代理

2017-05-09 23:54 by 陶俊龙, 261 阅读, 收藏,
摘要: var count = 10; for(var i = count;i--;){ var div = document.createElement('div'); div.innerHTML = "test_div"+i; div.className = "test_div"; document.b 阅读全文

js中闭包作用举例

2017-05-09 23:32 by 陶俊龙, 317 阅读, 收藏,
摘要: 模拟实现类的私有属性 function Boy(name){ this.name = name; var sex = 'boy'; this.saySex = function(){ console.log("my sex is "+sex) }; } var xiaoming = new Boy( 阅读全文

js typeof的使用

2017-05-09 23:21 by 陶俊龙, 357 阅读, 收藏,
摘要: console.log(typeof 1) console.log(typeof '1') console.log(typeof true) console.log(typeof undefined) console.log(typeof null) VM142:1 numberVM142:3 st 阅读全文

js new的理解

2017-05-09 22:42 by 陶俊龙, 276 阅读, 收藏,
摘要: function Cat(name, color){ this.name = name; this.color = color; } Cat.prototype.type = "猫科动物"; Cat.prototype.eat = function(){alert("吃老鼠");} var cat1 阅读全文