dimanche 19 avril 2015

Creating basic javascript library structure [on hold]

I'm interested in creating a basic javascript library structure ( structure because a library is a broad subject ). I looked at the jquery code for inspiration but there are things I don't understand.


Here is an example of what I don't understand:



(function( global, factory ) {
if ( typeof module === "object" && typeof module.exports === "object" ) {
module.exports = global.document ?
factory( global, true ) :
function( w ) {
if ( !w.document ) {
throw new Error( "jQuery requires a window with a document" );
}
return factory( w );
};
} else {
factory( global );
}
}(typeof window !== "undefined" ? window : this, function( window, noGlobal ){ ... }


Question:


What is happening in the code above? And is this needed to create the structure of a javascript library?


Thank you.


i don't know i saw it in every js lib!


Aucun commentaire:

Enregistrer un commentaire