疑难复习"/>
笔记:js疑难复习
笔记:js疑难复习
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: .html
DOM:(Document Object Model)文档对象模型
BOM:(Browser Object Mode) 浏览器对象模型
前端必备之JS继承方式总结(借用构造函数继承、原型链式继承、组合式继承、ES6中继承) 2017-9-22
.html JS实现继承的几种方式 2017-9-22
posted on 2017-09-09 01:41 bjhhh 阅读( ...) 评论( ...) 编辑 收藏
转载于:.html
更多推荐
笔记:js疑难复习
发布评论