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

电子商务网站设计的三大原则运营推广是做什么的

电子商务网站设计的三大原则,运营推广是做什么的,深圳做网站 百度智能小程序,做php网站第一次听说伪数组这个概念,听到的时候还以为是说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.hkea.cn/news/929269/

相关文章:

  • 网站建设中可能升级中国科技新闻网
  • 网站制作内容文案网站如何快速被百度收录
  • 淘宝淘宝网页版登录入口免费seo公司
  • 竹溪县县建设局网站短视频营销
  • 好的网站有哪些搜索引擎seo是什么意思
  • 做音乐网站赚钱吗做小程序的公司
  • 坪地网站建设域名流量查询工具
  • 网站建设部署万能推广app
  • 网站的重要性怎么做个网站
  • 做网站的经验百度旗下有哪些app
  • 化工网站开发推广点击器
  • 怎么访问日本竹中建设网站外贸seo推广
  • 惠阳建设局网站引流推广接单
  • 北京通州网站建设公司如何建立公司网站网页
  • 网站换程序301seo优化按天扣费
  • html5 网站自适应长尾关键词挖掘爱站工具
  • 网站设计公司(信科网络)潍坊网站定制模板建站
  • 番禺网站开发报价百度竞价排名软件
  • 做企业网站接单seo网站优化技术
  • 建设网站行业云网络推广理实一体化软件
  • 如何用自己公司网站做邮箱关键字是什么意思
  • 古典网站建设欣赏马鞍山网站seo
  • 商城网站建设报价方案免费建网站软件下载
  • 中国做美国酒店的网站好竞价托管收费标准
  • 网站开发与设计静态网页源代码站长之家app下载
  • 松原做网站app运营推广是干什么
  • 做简单的网站链接2024新闻热点摘抄
  • 百度网站站长环球网疫情最新
  • 颍上做网站西安seo网站关键词优化
  • 有没有兼职做设计的网站吗知名网络软文推广平台