笔记:js疑难复习

编程入门 行业动态 更新时间:2024-10-23 17:30:04

笔记:js<a href=https://www.elefans.com/category/jswz/34/1760068.html style=疑难复习"/>

笔记: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疑难复习

本文发布于:2024-02-06 15:40:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1749790.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:疑难   笔记   js

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!