Env.js
To load jQuery in SpiderMonkey’s js
console you should emulate browser’s
environment first. This can be done using envjs project,
originally
developed by John Resig.
Sadly, but only way to get it now is build manually from source, which will require java VM and ant… or you can just download compiled env.js (version 1.2.13) from my site.
Several people have troubles with using their own env.js, I don’t sure why - maybe something is wrong with latest versions or people compile it somehow in wrong way. If you have such troubles - try to download my version, it usually works ok. |
jQuery, plugins…
Download and save env.js, jQuery and selected plugins (I recommend at least jquery-dump) to disk.
Run!
js \
-f /path/to/env.js \
-e "Envjs.log=print;" \
-f /path/to/jquery-1.4.3.js \
-f /path/to/jquery.dump.js \
-i
Setup bash alias for ease
Add something like this to ~/.bashrc:
alias js=$(echo js \
-f ~/proj/js/envjs/env.js \
-e "\"Envjs.log=print;\"" \
-f ~/proj/js/jquery/jquery-1.4.3.js \
-f ~/proj/js/jquery-dump/jquery.dump.js \
-i)
It worked! :)
$ js
js> obj=$("<div><p>Ok</p></div>")
[object Object]
js> obj.find("p").html()
Ok
$ js -e 'print( $.dump( $("<p>Ok</p>") ) )'
jQuery Object {
0 = DOMElement [
nodeName: P
nodeValue: null
innerHTML: [
0 = String: Ok
]
]
}
… but it took a lot of time to load (on Core2Duo 6600):
$ time js -e 'print("ok")'
ok
real 0m0.417s
user 0m0.409s
sys 0m0.006s
$ time /usr/bin/js -e 'print("ok")'
ok
real 0m0.002s
user 0m0.000s
sys 0m0.001s