ファイルを渡せるのか…

// test.js
load('Array.js'); //あまり使えないArrayメソッドのかかれたファイルをロード
//複数ロードするときは load('Array.js','hogehoge.js',....)

a=[1,2,3,4,5]
b=[1,1,2,3,3,4,4,5]
c=[2,1,3,1,2,4,1,5]

print('exist:'+a.exist(3));
print('uniq 1:'+b.uniq());
print('uniq 2:'+c.uniq());

$ js test.js

exist:true
uniq 1:1,2,3,4,5
uniq 2:3,2,4,1,5

もっと早く気づいとくんだった。
いままではシェル起動して”js>"の後にいちいち打ち込んでた。


以下メモ。

js> help()
JavaScript-C 1.5 2004-09-24
Command   Usage                  Description
=======   =====                  ===========
version   version([number])      Get or set JavaScript version number
options   options([option ...])  Get or toggle JavaScript options
load      load(['foo.js' ...])   Load files named by string arguments
print     print([exp ...])       Evaluate and print expressions
help      help([name ...])       Display usage and help messages
quit      quit()                 Quit the shell
gc        gc()                   Run the garbage collector
trap      trap([fun, [pc,]] exp) Trap bytecode execution
untrap    untrap(fun[, pc])      Remove a trap
line2pc   line2pc([fun,] line)   Map line number to PC
pc2line   pc2line(fun[, pc])     Map PC to line number
build     build()                Show build date and time
clear     clear([obj])           Clear properties of object
intern    intern(str)            Internalize str in the atom table
clone     clone(fun[, scope])    Clone function object
seal      seal(obj[, deep])      Seal object, or object graph if deep

追記 20:51

vim

:%!js

で動作確認できるね。

さらに追記 9/9 18:50

上のだと置き換えてしまうのがちょっといやなので(uで戻ればいいけど),

:exe '!js %'

こっちのほうがよさそうだ。ほんとはステータス行の下のコマンド打つところに表示させたいんだけどどうやればいいんだろうか?調べる。