Rhino で無理やり prototype.js を使う
せっかく Rhino で prototype.js できると思ったら、そのまま使おうとしてもブラウザが持っているオブジェクトが見つからずにエラーが色々出てしまう。
そこで、エラーを1つひとつ調べて怒られる箇所にダミーのメソッドやプロパティを突っ込んでみまた。
// proto.js var window = { __head : null , HTMLElement : function(){ } } var navigator = { userAgent : "" } var document = { __head : null , createElement : function(){ return { __proto__ : null , appendChild : function(arg){ } } } , createEvent : function(arg){ return { __proto__ : null } } , createTextNode : function(arg){} , getElementById : function(id){ return { onreadystatechange : null } } , write : function(arg){} } function Element(){} function HTMLElement(){}
当然、画面系の処理はどんな動きになってしまうか分からない。
でも Class.* とかのメソッドは使えるようになったので、prototype.js の勉強にも Rhino を使っていけるかも。