在javascript中使用命名空间有什么好处? [英] What advantages are gained by using namespaces in javascript?

查看:63
本文介绍了在javascript中使用命名空间有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了不弄乱全局命名空间并获得将代码封装在私有成员中的能力之外,还有什么好处吗?

Apart from not cluttering the global namespace and gaining the ability to encapsulate code in private members, is there any benefit?

推荐答案

是的你是对的。除了名称空间的好处之外,名称空间没有任何好处。

Yes you're right. Apart from the benefits of namespaces, there are no benefits of namespaces.

但请务必考虑如果以后添加更多内容会发生什么外部脚本,或使您自己的脚本更复杂。命名空间非常轻巧,易于设置,从一开始就不会有害。

But be sure to consider what would happen if you later do add more external scripts, or make your own scripts more complicated. Namespaces are quite light and easy to set up, and it's never harmful to be tidy from the start.

这篇关于在javascript中使用命名空间有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆