What's the benefit of using extend.js?
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;
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' } } };
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.
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.
链接地址: http://www.djcxy.com/p/29812.html上一篇: 结合C ++和C
下一篇: 使用extend.js有什么好处?