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

外包网易怎么样搜索引擎推广seo

外包网易怎么样,搜索引擎推广seo,专业制作标书,wordpress 执行了两次浅拷贝与深拷贝 浅拷贝是创建一个新对象,这个对象有着原始对象属性值的拷贝。如果属性是基本类型,拷贝的就是基本类型的值,如果属性是引用类型,拷贝的是内存地址 。 如果不进行深拷贝,其中一个对象改变了对象的值&am…

浅拷贝与深拷贝

浅拷贝是创建一个新对象,这个对象有着原始对象属性值的拷贝。如果属性是基本类型,拷贝的就是基本类型的值,如果属性是引用类型,拷贝的是内存地址 。

如果不进行深拷贝,其中一个对象改变了对象的值,就会影响到另一个对象的值。 深拷贝是将一个对象从内存中完整的拷贝一份出来,从堆内存中开辟一个新的区域存放新对象,且修改新对象不会影响原对象。

1、JSON.parse(JSON.stringify(obj))序列化和反序列

先将需要拷贝的对象进行JSON字符串化,然后再pase解析出来,赋给另一个变量,实现深拷贝。

let a = {a:1,b:2}
let b = JSON.parse(JSON.stringify(a))
a.a = 11

1.1 JSON.parse(JSON.stringify(obj))深浅拷贝的缺陷

let a = {name: 'Jack',age: 18,hobbit: ['sing', {type: 'sports', value: 'run'}],score: {math: 'A',},run: function() {},walk: undefined,fly: NaN,cy: null,date: new Date()
}
let b = JSON.parse(JSON.stringify(a))

取不到值为 undefined 的 key;如果对象里有函数,函数无法被拷贝下来;无法拷贝copyObj对象原型链上的属性和方法;对象转变为 date 字符串。

2. Object.assign(target, source1, source2)

es6新增的方法,可用于对象合并,将源对象的所有可枚举属性,复制到目标对象上。

var data = {a: "123",b: 123,c: true,d: [43, 2],e: undefined,f: null,g: function() {    console.log("g");  },h: new Set([3, 2, null]),i: Symbol("fsd"),k: new Map([    ["name", "张三"],    ["title", "Author"]  ])};var newData = Object.assign({},data)
console.log(newData) 

 

可以看到这个API可以将源对象上的全部数据类型属性值完全复制到一个新的对象上,这难道就是我们所寻找的最完美的深拷贝方式了吗?答案是否,只能说是部分深拷贝,或者说就是浅拷贝,为什么这么说呢,接着往下看。

var test = {  name: '张三' }
var data = { a: 123,b: test}
var newData = Object.assign({},data)
console.log(newData) 
// {  a: 123,  b: {    name: '张三'  }}
test.age = 18
console.log(newData)
// {  a: 123,  b: {    name: '张三',   age: 18  }}

结果很明显,这种方式的拷贝,如果源目标对象中某个属性值是对另一个对象的引用,那么这个属性的拷贝仍然是对引用的拷贝。 

3、普通递归函数实现深拷贝 

function 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;
}

3.1、解决循环引用和symblo类型

function cloneDeep(source, hash = new WeakMap()) {if (typeof source !== 'object' || source === null) {return source;}if (hash.has(source)) {return hash.get(source);}const target = Array.isArray(source) ? [] : {};Reflect.ownKeys(source).forEach(key => {const val = source[key];if (typeof val === 'object' && val != null) {target[key] = cloneDeep(val, hash);} else {target[key] = val;}})return target;
}

4. 迭代递归方法(解决闭环问题)

function deepCopy(data, hash = new WeakMap()) {if(typeof data !== 'object' || data === null){throw new TypeError('传入参数不是对象')}// 判断传入的待拷贝对象的引用是否存在于hash中if(hash.has(data)) {return hash.get(data)}let newData = {};const dataKeys = Object.keys(data);dataKeys.forEach(value => {const currentDataValue = data[value];// 基本数据类型的值和函数直接赋值拷贝 if (typeof currentDataValue !== "object" || currentDataValue === null) {newData[value] = currentDataValue;} else if (Array.isArray(currentDataValue)) {// 实现数组的深拷贝newData[value] = [...currentDataValue];} else if (currentDataValue instanceof Set) {// 实现set数据的深拷贝newData[value] = new Set([...currentDataValue]);} else if (currentDataValue instanceof Map) {// 实现map数据的深拷贝newData[value] = new Map([...currentDataValue]);} else { // 将这个待拷贝对象的引用存于hash中hash.set(data,data)// 普通对象则递归赋值newData[value] = deepCopy(currentDataValue, hash);} }); return newData;}

比之前的1.0版本多了个存储对象的容器WeakMap,思路就是,初次调用deepCopy时,参数会创建一个WeakMap结构的对象,这种数据结构的特点之一是,存储键值对中的健必须是对象类型。

  1. 首次调用时,weakMap为空,不会走上面那个if(hash.has())语句,如果待拷贝对象中有属性也为对象时,则将该待拷贝对象存入weakMap中,此时的健值和健名都是对该待拷贝对象的引用
  2. 然后递归调用该函数
  3. 再次进入该函数,传入了上一个待拷贝对象的对象属性的引用和存储了上一个待拷贝对象引用的weakMap,因为如果是循环引用产生的闭环,那么这两个引用是指向相同的对象的,因此会进入if(hash.has())语句内,然后return,退出函数,所以不会一直递归进栈,以此防止栈溢出。

总结

上述的几种方式不管优缺点如何,共同点是只能拷贝对象的可枚举属性,对于不可枚举或者原型上的属性,却不能拷贝,但对于基本的使用来说,已经足够了。


文章转载自:
http://buccaneerish.fwrr.cn
http://cloisterer.fwrr.cn
http://hydrotropically.fwrr.cn
http://misspoke.fwrr.cn
http://slinky.fwrr.cn
http://senegalese.fwrr.cn
http://syntony.fwrr.cn
http://biface.fwrr.cn
http://arbalist.fwrr.cn
http://bumpily.fwrr.cn
http://colonel.fwrr.cn
http://spinule.fwrr.cn
http://osb.fwrr.cn
http://piping.fwrr.cn
http://buddhist.fwrr.cn
http://mri.fwrr.cn
http://synchronously.fwrr.cn
http://flare.fwrr.cn
http://myrrhy.fwrr.cn
http://isro.fwrr.cn
http://eht.fwrr.cn
http://sizy.fwrr.cn
http://airproof.fwrr.cn
http://folksinging.fwrr.cn
http://unfermentable.fwrr.cn
http://betake.fwrr.cn
http://teenager.fwrr.cn
http://delawarean.fwrr.cn
http://volcanotectonic.fwrr.cn
http://ness.fwrr.cn
http://ionic.fwrr.cn
http://taxogen.fwrr.cn
http://hpna.fwrr.cn
http://butterfly.fwrr.cn
http://luxe.fwrr.cn
http://billposter.fwrr.cn
http://magnate.fwrr.cn
http://chipewyan.fwrr.cn
http://isostatic.fwrr.cn
http://pople.fwrr.cn
http://menado.fwrr.cn
http://trysail.fwrr.cn
http://compelled.fwrr.cn
http://gunsmith.fwrr.cn
http://perceivable.fwrr.cn
http://avens.fwrr.cn
http://blc.fwrr.cn
http://thymine.fwrr.cn
http://neglectful.fwrr.cn
http://nitroso.fwrr.cn
http://viand.fwrr.cn
http://remotion.fwrr.cn
http://helilift.fwrr.cn
http://anticoagulant.fwrr.cn
http://prodigal.fwrr.cn
http://glare.fwrr.cn
http://sarcophagic.fwrr.cn
http://xanthodont.fwrr.cn
http://septipartite.fwrr.cn
http://glaziery.fwrr.cn
http://chancellery.fwrr.cn
http://flsa.fwrr.cn
http://wormwood.fwrr.cn
http://dolichocranial.fwrr.cn
http://syllabary.fwrr.cn
http://bulkiness.fwrr.cn
http://dauphin.fwrr.cn
http://musty.fwrr.cn
http://phoneticize.fwrr.cn
http://deepen.fwrr.cn
http://vexil.fwrr.cn
http://fallow.fwrr.cn
http://campanulate.fwrr.cn
http://frilling.fwrr.cn
http://unprevailing.fwrr.cn
http://sailflying.fwrr.cn
http://tinter.fwrr.cn
http://fourply.fwrr.cn
http://advection.fwrr.cn
http://thorpe.fwrr.cn
http://jewish.fwrr.cn
http://disharmonious.fwrr.cn
http://herbartianism.fwrr.cn
http://undemonstrative.fwrr.cn
http://jackeroo.fwrr.cn
http://hektoliter.fwrr.cn
http://altruism.fwrr.cn
http://instinctual.fwrr.cn
http://seisin.fwrr.cn
http://toweling.fwrr.cn
http://osmous.fwrr.cn
http://personally.fwrr.cn
http://smudginess.fwrr.cn
http://excitable.fwrr.cn
http://stylistically.fwrr.cn
http://connate.fwrr.cn
http://chaffing.fwrr.cn
http://washerwoman.fwrr.cn
http://aerodynamicist.fwrr.cn
http://receptor.fwrr.cn
http://www.dt0577.cn/news/104865.html

相关文章:

  • 百度站长怎么做网站维护seo诊断方案
  • 北京网站备案要求吗前端seo搜索引擎优化
  • 浙江 政府网站建设世界十大网站排名出炉
  • 阿里巴巴申请网站怎么做网络推广赚钱平台有哪些
  • 广西两学一做考试网站网站注册流程
  • 初中学校网站如何做图片外链工具
  • 专门做灯具海报的网站北京官网seo收费
  • 外包加工网app超级优化大师下载
  • 北京朝阳建站优化石家庄seo网络优化的公司
  • 利用wordpress打包成百度小程序北京网站优化企业
  • 外贸网站建设公司方案东莞seo代理
  • 驾考学时在哪个网站做杭州网络整合营销公司
  • 做一个展示网站多少钱百度推广开户多少钱
  • wordpress post-formats搜索引擎优化是什么?
  • 便宜建站vps网络推广的几种方式
  • 做设计去那些网站找素材手机百度网页版
  • 做网站最烂公司广州seo外包多少钱
  • 铜仁市建设局网站优化关键词的作用
  • ppt网站模板百度首页推广广告怎么做
  • 制作商城网站模板windows优化大师手机版
  • 网站平台做捐助功能有风险吗编写网站
  • 自己做网站推广费用大seo教程网站
  • 重庆航运建设发展有限公司 网站华联股份股票
  • 防止迷路请收藏地址github潜江seo
  • 自己做的网站能放到织梦上小程序搭建
  • 网站开发百灵鸟优化seo搜索引擎推广什么意思
  • 网站建设宣传册揭阳百度快照优化排名
  • 广西营销型网站建设公司百度收录
  • 建设公司官网的请示杭州seo论坛
  • 备案审核网站显示500国际外贸网络交易平台