你的心如利箭 在风中笔直的飞翔
github DNS ALEXA CDN
jquery JS CSS CSS3 HTML5 svg php --- isux w3cplus

21270

  博客园  :: 首页  ::  ::  ::  :: 管理

 

apply 和 call的区别

call 和 apply 的区别只在于这两个函数接受的参数形式不同

var Person = function(name,age){
    this.name = name;
    this.age = age;
}
Person.prototype.say=function(){
    return this.name;
}

var p1 = new Person('测试1号',20);
var p2 = new Person('测试2号',65);
console.log(p1.say());

Person.call(p1, '测试1号call', 22);//call 需要把参数按顺序传递进去(你的参数是明确知道数量时,用 call)
console.log(p1.say());

Person.apply(p1, ['测试1号apply', 23]);//apply 则是把参数放在数组里(你的参数不确定的时候,用 apply)
console.log(p1.say());

console.log(p2.say());

 

数组:

var arr = [1,2,3,4,5];
arr.forEach(                     //forEach (让数组中的每一项做一件事)
    function(item,index){console.log(item);}
);

var arr2 = arr.map(             //map (让数组通过某种计算产生一个新数组)
    function(item,index){return item * 2;}
);
console.log(arr2);

var arr3 = arr.filter(          //filter (筛选出数组中符合条件的项,组成新数组)
    function(item,index){return item>3;}
);
console.log(arr3);

var result = arr.reduce(        //reduce (让数组中的前项和后项做某种计算,并累积最终值)
    function(prev,next){return prev+next;}
);
console.log(result);

var result = arr.every(        //every (检测数组中每一项是否符合条件)
    function(item,index){return item>0;}
);
console.log(result);//因为满足全部条件,所以这里为 true

 

DOM 和 BOM:  http://www.cnblogs.com/chaoquan/p/7451881.html

DOM:(Document Object Model)文档对象模型
BOM:(Browser Object Mode) 浏览器对象模型

 

 

 

 

http://www.imooc.com/article/20162  前端必备之JS继承方式总结(借用构造函数继承、原型链式继承、组合式继承、ES6中继承)  2017-9-22

http://www.cnblogs.com/humin/p/4556820.html  JS实现继承的几种方式  2017-9-22

 

posted on 2017-09-09 01:41  bjhhh  阅读(208)  评论(0编辑  收藏  举报