JQuery Summary

In these talks by Nicholas Zakas and Addy Osmani they discuss the idea of using the facade pattern as a sandbox when building large scale Javascript applications, in order to decouple the application from the underlying base libraries.

This decoupling would in theory allow you to switch out a base library without needing to rewrite your application modules. However in practice this seems to be more difficult to implement.

There are concrete implementations of this proposed architecture, such as AuraJS . However from looking at the source it seems that the sandbox still has leaky abstractions by returning jQuery objects from some of its methods.

I'm not concerned with AuraJS specifically, but more the general concept of trying to abstract a library like jQuery without losing so much functionality.

As an example, say my facade/sandbox has a dom method .find(selector) . I can think of 3 options for what it might return:

  1. A jQuery object - This would leak jQuery out into the consuming modules.

  2. A raw dom element - Loss of functionality, nobody really wants to work with this! No chaining.

  3. A custom jQuery-like wrapper - Could be quite complex, but seems like the ideal solution.

So my question is, how would you abstract a library like jQuery without losing too much functionality, such that it could be replaced at some point in the future with minimal effort?

我来评几句
登录后评论

已发表评论数()

相关站点

+订阅
热门文章