当前位置: 首页 > news >正文

闲鱼怎么做钓鱼网站杭州百度快照优化公司

闲鱼怎么做钓鱼网站,杭州百度快照优化公司,wordpress网站换主题,关于动物自己做的网站第一次听说伪数组这个概念,听到的时候还以为是说CSS的伪类呢,网上一查,这东西原来还是个很常见的家伙。 何为伪数组 伪数组有两个特点: 具有length属性,其他属性(索引)为非负整数但是却不具备…

第一次听说伪数组这个概念,听到的时候还以为是说CSS的伪类呢,网上一查,这东西原来还是个很常见的家伙。

何为伪数组

伪数组有两个特点:

  1. 具有length属性,其他属性(索引)为非负整数
  2. 但是却不具备数组的方法
    也就是看起来像是数组,然而并不是…

举个例子看看

  1. 函数内部的arguments
function testArguments(a, b, c) {console.log(`arguments is array: ${Array.isArray(arguments)}`);console.log(arguments[0]);console.log(arguments[1]);console.log(arguments[2]);
}
testArguments(1,2,3);

test result
2. DOM列表

  1. JQuery选择得出的列表: $(‘div’)
    随意找一个使用jq的网站,例如:https://www.jq22.com/

如何判断真伪数组

  1. 使用instanceof 方法
  2. 使用Array.isArray()方法: 未必准确,见下文, 使用伪数组.__proto__ = Array.prototype;转换后不可用。
  3. 伪数组.constructor === Array; 适用于带constructor的场景
  4. Object.prototype.toString.call(arr) === ‘[object Array]’

尝试一下:

function testArguments(a, b, c) {console.log(`arguments is array: ${Array.isArray(arguments)}`);console.log(`arguments is array: ${arguments instanceof Array}`);console.log(`arguments is object: ${arguments instanceof Object}`);const newArguments = Array.prototype.slice.call(arguments);console.log(`newArguments is array: ${Array.isArray(newArguments)}`);console.log(`newArguments is array: ${newArguments instanceof Array}`);console.log(`newArguments is object: ${newArguments instanceof Object}`);
}testArguments(1,2,3);

如何把伪数组转换成数组

  1. Array.prototype.slice.call(); / Array.prototype.slice.apply();
  2. 原型继承: 伪数组.__proto__ = Array.prototype;arguments 无影响正常使用
  3. ES6中数组的新方法 from()
方法一: Array.prototype.slice.call(); / Array.prototype.slice.apply();
function testArguments(a, b, c) {console.log(`arguments is array: ${Array.isArray(arguments)}`);console.log(arguments[0]);console.log(arguments[1]);console.log(arguments[2]);const newArguments = Array.prototype.slice.call(arguments);console.log(`newArguments is array: ${Array.isArray(newArguments)}`);console.log(newArguments[0]);console.log(newArguments[1]);console.log(newArguments[2]);
}
testArguments(1,2,3);

方法二: 原型继承: 伪数组.__proto__ = Array.prototype;arguments 无影响正常使用
使用该方法进行转换时,Array.isArray()方法不可用来进行判断。

方法三: ES6中数组的新方法 from()

尝试一下:

function testArguments(a, b, c) {console.log(`arguments is array: ${Array.isArray(arguments)}`);console.log(`arguments is array: ${arguments instanceof Array}`);const newArguments = Array.from(arguments);console.log(`newArguments is array: ${Array.isArray(newArguments)}`);console.log(`newArguments is array: ${newArguments instanceof Array}`);
}
testArguments(1,2,3);

总结

  1. 在使用判断是否为数组时,如果无法知道数组是否可能是使用“原型继承”的方法转换得到的,就不要使用Array.isArray()方法判断对象是否为数组的方法。
  2. 在写转换方法时,由于原型继承: 伪数组.__proto__ = Array.prototype;可能存在判断失误,尽量使用Array.prototype.slice.call(); / Array.prototype.slice.apply();如果可以使用ES6,使用Array.from()方法较为简单明了。
http://www.dinnco.com/news/18303.html

相关文章:

  • 毕设给学校做网站网站关键词排名外包
  • 网站网络设计是怎么做的营销型高端网站建设
  • 帮做网站设计与规划作业啥都能看的浏览器
  • 模拟ip访问网站欧洲网站服务器
  • 网站建设进度图怀来网站seo
  • 网站上seo怎么做网推项目
  • 苏州企业网站建设设计ui培训
  • 泰安电视台新闻综合频道百度关键词优化系统
  • 网站建设需要什么人员网络优化的流程
  • 罗湖附近公司做网站建设哪家效益快品牌推广外包
  • 电子商务网站建设专业主修课程3a汽车集团公司网络营销方案
  • wordpress wpdx教程宁波正规优化seo软件
  • 淘宝客网站一般用什么做的搜索引擎优化培训班
  • 办公设备网站推广怎么做淘大象排名查询
  • 现在做个企业网站一般多少钱seo网站seo
  • 手机网站免费制作平台最新国际新闻头条新闻
  • 做网站哪种字体好看专业关键词排名优化软件
  • 做商城网站的企业推广策划方案
  • 温州企业模板建站百度seo排名优化
  • 免费做app的网站有哪些营销手段有哪些方式
  • 招聘网站怎么做线下活动百度广告联盟收益
  • 网站式的公司记录怎么做网络科技公司
  • 网站如何引入流量怎么查询百度收录情况
  • 网站建设优化公司呼和浩特设计师培训班多少钱
  • 乌鲁木齐建设网络优化大师客服
  • 安吉做网站免费seo网站的工具
  • 三沙网站设计公司爱站关键词挖掘old
  • 做外贸 建网站要注意什么重庆网络推广公司
  • 商城网站制作报价债务优化是什么意思
  • 网站外部链接怎么做天津网站排名提升