conardli / conardli.github.io Goto Github PK
View Code? Open in Web Editor NEWConardLi 写 blog 的地方
Home Page: https://blog.conardli.top/
ConardLi 写 blog 的地方
Home Page: https://blog.conardli.top/
你好最近拜读了您的文章发现写的非常不错,我前前后后读了好几遍 当我去实现的时候我发现了一个问题,在深拷贝函数处理对象或者数组的这个阶段里 我觉得应该要将 symbol 属性加上 Object.keys()
并不能获得健为 symbol
的 value
或许这里应该获得包含 symbol
的属性应该要好一些
let target = {
field1:1,
field2:[1,2,3,4],
field3:'ConardLi',
field4:{
child:'child',
child2:{
child:'child2'
}
}
}
target.target = [12,23] 比如说这种,这时候拷贝出来的target就出现错误了
读了下发现部分代码是多余的:
经过isObject后,显然(Number String Boolean Symbol Undefined Null)这些类型都是不会往下走的而是直接返回的
但是发现cloneOtherType还是有对(Number String Boolean Symbol )的处理,我认为后面应该是没有必要再处理的
赞
我对clone4的DEMO文件涉及到的WHILE循环的效率表示质疑,本地测试到的结果(node环境):
clone1 在前,clone2在后, 结果:
undefined: 0.167ms
undefined: 0.126ms
将 clone1 跟 clone2 调下位置,即clone2放在前面,结果:
undefined: 0.254ms
undefined: 0.081ms
即所消耗的时间跟调用的先后顺序有关,而不是WHILE循环的优化结果,不知你怎么看?
window.postMessage() 方法可以安全地实现跨源通信。通常,对于两个不同页面的脚本,只有当执行它们的页面位于具有相同的协议(通常为https),端口号(443为https的默认值),以及主机 (两个页面的模数 Document.domain设置为相同的值) 时,这两个脚本才能相互通信。window.postMessage() 方法提供了一种受控机制来规避此限制,只要正确的使用,这种方法就很安全。
MDN postMessage
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.