加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 我应该使用Angular.copy()或_.clone()?

发布时间:2020-12-17 08:49:07 所属栏目:安全 来源:网络整理
导读:我正在一个项目,有Angular和Underscore作为依赖。 当我需要创建一个对象的副本,根据我的心情,当时,我可能使用angular.copy()或_.clone() 我发现这些方法之一可能比另一个更快,可靠/鲁棒。 是否有任何已知的问题,这些功能,使它比其他更好或更差的使用
我正在一个项目,有Angular和Underscore作为依赖。

当我需要创建一个对象的副本,根据我的心情,当时,我可能使用angular.copy()或_.clone()

我发现这些方法之一可能比另一个更快,可靠/鲁棒。

是否有任何已知的问题,这些功能,使它比其他更好或更差的使用,假设两个库已经包括?

关于你的问题:angular.copy和_.clone是不同的。这不是一个问题,哪个更好,它是关于你需要什么@凯文B在评论中说。

另一方面,angular.extend()是一个浅拷贝类似于_.clone

Angular.copy vs Angular.extend

性能明智,我不知道哪个更好,但为了意见,我反对包括库到任何角度应用程序的全局范围(下划线),因为通常这些东西写作angular modules. angular.copy / angular .extend在这种情况下会胜出。

浅/深复制:

Its very simple that if the object has only primitive fields,then obviously you will go for shallow copy but if the object has references to other objects,then based on the requiement,shallow copy or deep copy should be chosen. What I mean here is,if the references are not modified anytime,then there is no point in going for deep copy. You can just opt shallow copy. But if the references are modified often,then you need to go for deep copy. Again there is no hard and fast rule,it all depends on the requirement.

Source

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读