使用extend.js有什么好处? [英] What's the benefit of using extend.js?

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

问题描述

我刚认识 extend.js ,想知道与使用本机JavaScript相比,使用库是否有附加值。让我演示一下;

I just got acquainted with extend.js, and was wondering if there's an added value to using the library over using native JavaScript. Let me demonstrate;

使用 extend.js ,我将这样声明一个命名空间:

With extend.js, I would declare a namespace like so:

extend('some.madeup.namespace',{
   foo : 'bar'
});

…否则,我只需要这样做:

… whereas without it, I'd only have to do that:

var some = { madeup : { namespace : { foo : 'bar' } } };

我坚信KISS原则,我真的认为应该将外部依赖减少到使事情变得更简单。因此,如果该库所做的只是为我节省了(一次)赋值声明,我会考虑是否值得这样做。

I'm a firm believer in the KISS principle, and I really think external dependencies should be reduced to make things a little bit simpler. So, if all this library does is save me the (one-time) assignment declaration, I ponder if it's worth the trouble.

这里是否缺少任何内容,这就是全部吗?

Is there anything I'm missing here, is this all there's to it?

推荐答案

我怀疑这个问题的明智答案很大程度上取决于任何三分之一的通用答案

I suspect a sensible answer to this question leans heavily on a generic answer for any third party tool.

人们使用第三方工具来帮助他们更快,更优雅地完成工作,至少这是理论。但是有些人,包括我自己在内,发现减少依赖并从头开始实现会更加优雅。对我们来说,在项目中包含糖几乎没有价值,因为这会使我们的原则贬值。

People use third party tools when it helps them get the job done faster and more elegantly, at least that's the theory. But there are people, myself included who find it more elegant to reduce dependencies and to implement from scratch. To us there is little value in including sugar in our projects, because this devalues our principles.

对其他人而言,它具有价值,因为它减少了他们必须编写的代码量也许感觉有点结构化。他们本来会做出相同的抽象,所以使用经过深思熟虑和经过测试的库是有意义的。

To others it has values because it reduces the amount of code they have to write and perhaps feels slightly more structured. They would have made the same abstraction themselves, so it makes sense to use a well thought out and tested library.

它在很大程度上取决于您的个人喜好和用法。诚然,我还没有特别解决这个库的用法,它只有51行代码。阅读它提供的功能并得出自己的结论不应该花很长时间。

It weights heavily on your personal preferences and usage. Admittedly I have not addressed the usage of this library in particular, it is only 51 lines of code. It shouldn't take long to read over the features it's providing and to come to your own conclusions.

据我所知,该库仅创建名称空间层次结构并检查冲突的名称空间。大多数代码似乎都集中在创建层次结构和验证名称空间的区别性上。对我来说,这表明它已被设计为在可能发生冲突的情况下用作通用工具-假设您正在发布自己的库以进行大量消费。

From what I can tell this library merely creates namespace hierarchies and checks for conflicting namespaces. Most of the code seems to be focused of creating the hierarchy and verifying namespace distinctness. This would suggest to me it's been designed as a general purpose tool in situations where conflicts might occur - say you are publishing your own library for mass consuption.

但是,它是来自一个不会选择使用它的人。命名空间实际上是不必要的。如果您实际上担心名称空间冲突,那么为防止窗口上的多个名称空间冲突所做的所有努力听起来确实是必要的,但是任何好的设计都不会。

If you want my opinion though, it would be from a person who wouldn't use it by choice. Namespaces are actually unnecessary. All that effort to prevent multiple namespace conflicts on window does sound necessary if you are actually concerned about conflicting namespaces, but any good design never would be.

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

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