javascript - Wrap jQuery, dojo with custom library? -


coming java, i'm wondering if java best practice applies javascript.

in java, there's separation of interface , implementation, , mixing them considered bad practice. same token, recommended hide implementation details of library end developers.

for example, log4j 1 of popular logging libraries out there recommended write code slf4j library or commons logging library "wraps" log4j. way, if choose switch logging framework such logback, can without changing code. reason you, user of logging library, how logging done none of concern, long know logging does.

so javascript, non-trivial web applications have own custom javascript libraries, many of use open source libraries such jquery , dojo. if custom library depends on, jquery, not extension, implementation, see need add layer wraps jquery , makes transparent rest of javascript code?

for example, if have foo library contains custom, front-end logic, you'd introduce bar library wraps jquery. way, foo library use bar library jquery functions, totally oblivious jquery. in theory, switch other libraries such dojo , google web toolkit without having big impact on foo library.

do see practical value in this? overkill?

there lot of answers here, 1 thing don't see mentioned feature sets. if try write library wrap functionality provided by, say, jquery, want able swap out prototype, have problem. jquery library doesn't provide features prototype provides, , prototype doesn't provide features jquery provides. on top of that, both provide features in radically different ways (prototype extends base objects -- that's damn near impossible wrap).

in end, if tried wrap these libraries in code adds 'abstraction' try make them more flexible, you're going lose 80% of frameworks provided. you'll lose fancy interfaces provide (jquery provides awesome $('selector') function, prototype extends base objects), , you'll have decide if want leave out features. if given feature not provided both frameworks, have either ditch or reimplement other framework. big can of worms.

the whole problem stems fact java inflexible language. library provides functionality, , that's it. in javascript, language insanely flexible, , lets lots of crazy things (like writing library, , assigning $ variable). ability crazy things lets developers of javascript libraries provide creative functionality, means can't find commonalities in libraries , write abstraction. think writing javascript requires significant change in perspective java developer.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -