Last active
December 19, 2015 15:49
-
-
Save timmywil/5979255 to your computer and use it in GitHub Desktop.
Using jQuery in a CommonJS-like environment and multiple contexts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This can be done with what is currently in github (but has not yet been released) | |
// Using jsdom | |
var dom = jsdom.jsdom(); | |
var window = dom.createWindow(); | |
var window2 = dom.createWindow(); | |
var factory = require('jquery'); | |
var jquery1 = factory( window ); | |
var jquery2 = factory( window2 ); | |
// Browserify | |
var factory = require('jquery'); | |
var jQuery = factory(); | |
var anotherjQuery = factory(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Roughly I need to do this in browsers:
var jQuery = Function( 'global', '(' + factory + ')(global)' )( targetContext );
"factory" is just the string representation of the function that creates a new jQuery instance.
I will just simulate the Node way of achieving it using the module object as transport.