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

网站上传源码后怎么弄手机访问另一部手机访问文件

网站上传源码后怎么弄,手机访问另一部手机访问文件,精神文明建设网站模板,网站建设系统 招标文章目录 一、数组Array1、forEach2、filter3、map4、reduce5、find6、findIndex7、includes8、join 二、对象Object1、Object.keys2、深复制 js环境中有很多工具函数,比如es6添加了很多新的属性和方法,这些方法也可以自定义实现,但是官方也提…

文章目录

  • 一、数组Array
    • 1、forEach
    • 2、filter
    • 3、map
    • 4、reduce
    • 5、find
    • 6、findIndex
    • 7、includes
    • 8、join
  • 二、对象Object
    • 1、Object.keys
    • 2、深复制

js环境中有很多工具函数,比如es6添加了很多新的属性和方法,这些方法也可以自定义实现,但是官方也提供出来了(这样可以形成规范和一致性),了解为什么要提供这些函数是有必要的。

一、数组Array

公共数据

  const inventory = [{ name: "芦笋", type: "蔬菜", quantity: 5 },{ name: "香蕉", type: "水果", quantity: 0 },{ name: "山羊", type: "肉", quantity: 23 },{ name: "樱桃", type: "水果", quantity: 5 },{ name: "鱼", type: "肉", quantity: 22 }];

1、forEach

  // 自定义forEach方法Array.prototype.forEachCustom = function (cb) {// 这里的this是数组本身;if (!Array.isArray(this)) {return;}// 这里的cb是自定义的回调函数;if (typeof cb !== "function") {return;}for (let i = 0; i < this.length; i++) {// this[i], i, this 三个参数分别表示当前元素,索引,数组本身// 大部分功能函数都是这三个参数和顺序cb(this[i], i, this);}};// inventory.forEachCustom((item) => { // TEST//   console.log(item.name);// });

2、filter

  // 自定义filter方法Array.prototype.filterCustom = function (cb) {// 这里的this是数组本身;if (!Array.isArray(this)) {return;}// 这里的cb是自定义的回调函数;if (typeof cb !== "function") {return;}const result = [];for (let i = 0; i < this.length; i++) {// 返回值只是为了做if判断,不用存储;存储的是满足条件的元素if (cb(this[i], i, this)) {result.push(this[i]);}}return result;};const resultFilterCustom = inventory.filterCustom((item) => {return item.quantity >= 6;});// console.log("filterCustom", resultFilterCustom); // TEST

3、map

  // 自定义map方法Array.prototype.mapCustom = function (cb) {// 这里的this是数组本身;if (!Array.isArray(this)) {return;}// 这里的cb是自定义的回调函数;if (typeof cb !== "function") {return;}const result = [];for (let i = 0; i < this.length; i++) {// 将返回值存储起来,最后返回; 当然函数默认返回undefinedresult.push(cb(this[i], i, this));}return result;};const resultMapCustom = inventory.mapCustom((item) => {if (item.quantity >= 6) {return item.name;}});// console.log("mapCustom", resultMapCustom); // TEST

4、reduce

  // 自定义reduce方法Array.prototype.reduceCustom = function (cb, initialValue) {// 这里的this是数组本身;if (!Array.isArray(this)) {return;}// 这里的cb是自定义的回调函数;if (typeof cb !== "function") {return;}// 每一次循环的结果都会作为下一次循环的初始值; 最后返回出去let result = initialValue;for (let i = 0; i < this.length; i++) {result = cb(result, this[i], i, this);}return result;};const resultReduceCustom = inventory.reduceCustom((acc, item) => {return acc + item.quantity;}, 0);// console.log("reduceCustom", resultReduceCustom); // TEST

5、find

  // 自定义find方法Array.prototype.findCustom = function (cb) {// 这里的this是数组本身;if (!Array.isArray(this)) {return;}// 这里的cb是自定义的回调函数;if (typeof cb !== "function") {return;}for (let i = 0; i < this.length; i++) {// 返回值只是为了做if判断,不用存储;// 找到第一个满足条件的元素就返回,找到就停止遍历// 有点类似于filter,但是只返回第一个满足条件的元素if (cb(this[i], i, this)) {return this[i];}}// 如果没有找到,返回undefined};const resultFindCustom = inventory.findCustom((item) => {return item.name === "香蕉";});// console.log("findCustom", resultFindCustom); // TEST

6、findIndex

  // 自定义findIndex方法Array.prototype.findIndexCustom = function (cb) {// 这里的this是数组本身;if (!Array.isArray(this)) {return;}// 这里的cb是自定义的回调函数;if (typeof cb !== "function") {return;}for (let i = 0; i < this.length; i++) {// 返回索引,找到第一个满足条件的元素就返回,找到就停止遍历// 很类似于find,但是只返回第一个满足条件的元素的索引if (cb(this[i], i, this)) {return i;}}// 如果没有找到,返回-1};const resultFindIndexCustom = inventory.findIndexCustom((item) => {return item.name === "樱桃";});// console.log("findIndexCustom", resultFindIndexCustom); // TEST

7、includes

  // 自定义includes方法Array.prototype.includesCustom = function (value) {for (let i = 0; i < this.length; i++) {// 这里默认数组是一维数组; 只是单纯判断值是否存在;// 如果是复杂数据,使用find即可;if (this[i] === value) {return true;}}return false;};// console.log("includesCustom", [1, 2, 3, 4, 5].includesCustom(2)); // TEST

8、join

  // 自定义join方法Array.prototype.joinCustom = function (separator) {// 这里的this是数组本身;if (!Array.isArray(this)) {return;}// 这里的separator是自定义的分隔符;if (typeof separator !== "string") {return;}let result = "";for (let i = 0; i < this.length; i++) {// 这里默认数组是一维数组;// 这里默认separator是空格;result += this[i] + separator;}// 去掉最后一个分隔符;return result.slice(0, -1);};console.log("joinCustom", [1, 2, 3, 4, 5].joinCustom("-")); // TEST

二、对象Object

1、Object.keys

提供了一个案例,获取属性时的原型链问题

  // 简易版继承const parentFunc = function () {this.name = "张三";};const childFunc = function () {// 继承父类的属性和方法;构造函数继承;// 注意调用的时机,会决定实例的属性顺序;比如这里的name属性在age前面parentFunc.call(this);// 运行时this指向childFunc实例对象(的内存空间);this.age = 20;};parentFunc.prototype.getName = function () {return this.name;};childFunc.prototype = new parentFunc();const childObj = new childFunc();const keysAll = [];const keysOwn = [];for (let key in childObj) {// 自己的属性和原型链上的属性都会遍历出来;// 原型链继承的所有属性 + Object.prototype 挂载的自定义方法keysAll.push(key);if (childObj.hasOwnProperty(key)) {// 自己的属性才会遍历出来;keysOwn.push(key);}}console.log("Object.keysCustom", keysAll, keysOwn); // TEST// 结果:keysAll = ["name", "age", "getName", "keysCustom"];// 结果: keysOwn = ["name", "age"];// 自定义Object.keys方法   用于获取对象所有属性名Object.prototype.keysCustom = function (obj) {if (typeof obj !== "object" || obj === null) {return;}const result = []; // 用于存储结果for (let key in obj) {// hasOwnProperty表示自身的属性,不包括原型链上的属性if (obj.hasOwnProperty(key)) {// 相当于循环后存储keyresult.push(key);}}return result;};const obj = { name: "张三", age: 20, gender: "男" };// console.log("Object.keysCustom", Object.keysCustom(obj)); // TEST

2、深复制

  const data = [{ name: "张三", age: 20, array: [1, 2, 3] },{ name: "李四", age: 25, array: [4, 5, 6] }];const deepClone = (source) => {if (typeof source !== "object" || source == null) {return source;}const target = Array.isArray(source) ? [] : {};for (const key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {if (typeof source[key] === "object" && source[key] !== null) {target[key] = deepClone(source[key]);} else {target[key] = source[key];}}}return target;};console.log("deepCopy", deepClone(data)); // TEST

文章转载自:
http://assaultive.nLcw.cn
http://retiredness.nLcw.cn
http://hatrack.nLcw.cn
http://december.nLcw.cn
http://impartiality.nLcw.cn
http://feeble.nLcw.cn
http://chess.nLcw.cn
http://deductivism.nLcw.cn
http://protogyny.nLcw.cn
http://severity.nLcw.cn
http://chordate.nLcw.cn
http://imperceptible.nLcw.cn
http://rejectant.nLcw.cn
http://virid.nLcw.cn
http://sagger.nLcw.cn
http://maths.nLcw.cn
http://bodhidharma.nLcw.cn
http://openhanded.nLcw.cn
http://mousse.nLcw.cn
http://mantelshelf.nLcw.cn
http://actinolite.nLcw.cn
http://bp.nLcw.cn
http://thuggish.nLcw.cn
http://thermoelectron.nLcw.cn
http://chowhound.nLcw.cn
http://toyland.nLcw.cn
http://exultance.nLcw.cn
http://chordotonal.nLcw.cn
http://popover.nLcw.cn
http://aquacade.nLcw.cn
http://retake.nLcw.cn
http://seismal.nLcw.cn
http://enchanting.nLcw.cn
http://voom.nLcw.cn
http://triennium.nLcw.cn
http://satyarahi.nLcw.cn
http://wallcovering.nLcw.cn
http://sequel.nLcw.cn
http://exoerythrocytic.nLcw.cn
http://inseverable.nLcw.cn
http://insalivate.nLcw.cn
http://uma.nLcw.cn
http://raffinate.nLcw.cn
http://chauffeuse.nLcw.cn
http://triphibian.nLcw.cn
http://barm.nLcw.cn
http://haussa.nLcw.cn
http://priming.nLcw.cn
http://gospel.nLcw.cn
http://ultracytochemistry.nLcw.cn
http://sahelian.nLcw.cn
http://comitragedy.nLcw.cn
http://untapped.nLcw.cn
http://biovular.nLcw.cn
http://rubbaboo.nLcw.cn
http://fleming.nLcw.cn
http://upsoar.nLcw.cn
http://nomadise.nLcw.cn
http://cytotechnology.nLcw.cn
http://beholden.nLcw.cn
http://pully.nLcw.cn
http://coaxingly.nLcw.cn
http://gruntled.nLcw.cn
http://swede.nLcw.cn
http://pernik.nLcw.cn
http://oozy.nLcw.cn
http://eurhythmic.nLcw.cn
http://dengue.nLcw.cn
http://programer.nLcw.cn
http://blether.nLcw.cn
http://granth.nLcw.cn
http://schedular.nLcw.cn
http://parthenope.nLcw.cn
http://decontrol.nLcw.cn
http://terrifically.nLcw.cn
http://pepsi.nLcw.cn
http://cyanize.nLcw.cn
http://fibrocystic.nLcw.cn
http://pamplegia.nLcw.cn
http://factiously.nLcw.cn
http://scallion.nLcw.cn
http://evasively.nLcw.cn
http://medical.nLcw.cn
http://chlorophyllite.nLcw.cn
http://smithereen.nLcw.cn
http://coehorn.nLcw.cn
http://pardah.nLcw.cn
http://immiscible.nLcw.cn
http://parvalbumin.nLcw.cn
http://entoilment.nLcw.cn
http://greycing.nLcw.cn
http://nonpositive.nLcw.cn
http://ectogenic.nLcw.cn
http://seriousness.nLcw.cn
http://bie.nLcw.cn
http://aconitum.nLcw.cn
http://trivia.nLcw.cn
http://ethionine.nLcw.cn
http://testibiopalladite.nLcw.cn
http://crinite.nLcw.cn
http://www.15wanjia.com/news/94945.html

相关文章:

  • 做商铺最好的网站淘宝宝贝排名查询
  • 旅游网站开发实验报告挖掘关键词爱站网
  • 怎么做响应式网站深圳网络推广建站
  • 网站icp备案号是如何编制的全国最好的广告公司加盟
  • 南京 网站开发国外网站排名前十
  • 学完js了可以做哪些网站优化设计的答案
  • 范文网站学校技防 物防建设一站式营销推广
  • PHP网站开发工程师招聘厦门头条今日新闻
  • 阿里云轻应用服务器 建设网站日本网站源码
  • 微信朋友圈投放广告刷网站seo排名软件
  • 那个外贸网站做的最好seo优化教程培训
  • 自己做的网站图片无法显示搭建一个app平台要多少钱
  • wordpress怎么搜站点seo是什么服务器
  • 团购网站 设计方案昭通网站seo
  • 网站开发功能需求文档十大小说网站排名
  • 做网站需提供什么资料如何做网络营销
  • 做任务赚佣金网站有哪些百度手机卫士
  • 工信部网站备案查询步骤小程序开发一个多少钱啊
  • 隆尧企业做网站百度校招
  • 深圳深度网站建设微软优化大师
  • 互联网 网站建设拉新推广
  • 中国建设厅官方网站平台网站开发公司
  • 网站根目录是哪个文件夹如何进行网站的宣传和推广
  • 河南网络科技网站建设湖南官网网站推广软件
  • 龙华专业做网站头条收录提交入口
  • 企业网站优化外包免费建立个人网站官网
  • 网站建设头部代码在哪买网站链接
  • 蓬莱建网站安装百度到桌面
  • 网站制作需要哪些东西精准营销
  • 如何做简易个人网站google广告