2016年1月27日

对象作为 handleEvent

摘要: elem.addEventListener("click", obj, false); //用对象作为处理函数var obj = { handleEvent: function(event) { ....... }}会自动运行 handleEvent 这个方法 阅读全文

posted @ 2016-01-27 10:27 迷茫小飞侠 阅读(152) 评论(0) 推荐(0) 编辑

Module模式

摘要: 匿名函数闭包(function () { // ... all vars and functions are in this scope only // still maintains access to all globals}()); 注意在匿名函数外面的括号。这是由于在JavaS... 阅读全文

posted @ 2016-01-27 10:26 迷茫小飞侠 阅读(166) 评论(0) 推荐(0) 编辑

arrow functions 箭头函数

摘要: ES6里新增加的,与普通方法不同的地方1、this 的对象在定义函数的时候确定了,而不是在使用的时候才决定2、不可以使用 new ,也就不能当构造函数3、this 的值一旦确定无法修改在 ES5 下,定制sort比较函数:var result = values.sort(function(a, b)... 阅读全文

posted @ 2016-01-27 10:23 迷茫小飞侠 阅读(148) 评论(0) 推荐(0) 编辑

2016年1月26日

不使用类的继承,纯粹使用对象

摘要: var myMammal = { name : 'Herb the Mammal', get_name : function () { return this.name; }, says : function () { return this.saying || ''; }};var myCat =... 阅读全文

posted @ 2016-01-26 17:12 迷茫小飞侠 阅读(128) 评论(0) 推荐(0) 编辑

类(对象)的定义 自定义对象构造函数

摘要: 对象创建和继承对象创建指的是自定义对象构造函数,用于批量创建拥有共同属性方法的对象。例如创建一个人对象构造函数,然后实例化出小明,小红继承指的是两个引用类型对象间属性和方法的继承,原理是利用prototype,因为实例内部保留了对构造函数prototype的指针,prototype保留对该构造函数的... 阅读全文

posted @ 2016-01-26 17:11 迷茫小飞侠 阅读(506) 评论(0) 推荐(0) 编辑

数组删除操作 splice

摘要: 原理通过设置 函数的 length 属性var a = [1, 2, 3, 4];a.length = 3 ;结果 : a = [1,2,3] 阅读全文

posted @ 2016-01-26 17:08 迷茫小飞侠 阅读(145) 评论(0) 推荐(0) 编辑

继承

摘要: 继承主要就是通过prototype chaining 来实现的1、Prototype Chaining:function SuperType(){this.property = true;}SuperType.prototype.getSuperValue = function(){return t... 阅读全文

posted @ 2016-01-26 17:08 迷茫小飞侠 阅读(157) 评论(0) 推荐(0) 编辑

this 和 new 构造函数

摘要: function people(name) { 这样定义是在全局命名空间(global namespace) name: name, sayname: function() { alert(this.name); }}jack = people("jack"); 这个时候 this... 阅读全文

posted @ 2016-01-26 17:07 迷茫小飞侠 阅读(237) 评论(0) 推荐(0) 编辑

遍历数组 优化

摘要: var a, i = 0, arr = [1,2,3,4];while(a = arr[i++]){ alert(a) 输出 1,2,3,4}从零开始遍历数组,有点类似于for,但是while 不需要知道数组的长度,只要还有数据就会递增更好的遍历数组的方法var i,i... 阅读全文

posted @ 2016-01-26 17:06 迷茫小飞侠 阅读(471) 评论(0) 推荐(0) 编辑

defaultView and parentWindow

摘要: defaultView 只读的which is used to represent the currently rendered view of the document返回的值通常是包含目前document的 window对象ie9 开始支持该属性,之前的版本使用 parentWindow 属... 阅读全文

posted @ 2016-01-26 17:06 迷茫小飞侠 阅读(204) 评论(0) 推荐(0) 编辑

导航