これを使うと
$.each([1,2,3], function(index, item) {
print("foo" + item);
});
$.ajax({
type: "GET",
url: "http://www.google.co.jp/",
async: false,
success: function(data) {
print(data);
}
});
こんなソースが実行出来ます。$.eachなんかは目茶目茶便利なので、使わない手はありません。とりあえず、$.ajaxでgoogle.co.jpのソースが取得出来るくらいは動きます。
以下全体ソース。
// vim:fdm=marker fdl=0 fdc=0 fdo+=jump,search:
// vim:fdt=substitute(getline(v\:foldstart),'\\(.\*\\){\\{3}','\\1',''):
// {{{
(function(target) {
target.window = {
document : {
defaultView : {}
},
navigator : {
userAgent : "Windows Scripting Host"
},
location : {},
XMLHttpRequest : function() {
// copied from http://la.ma.la/misc/js/ie_xmlhttp.js
var self = this;
var props = "readyState,responseText,responseXML,status,statusText".split(",");
this.readyState = 0;
this.__request__ = new ActiveXObject("Microsoft.XMLHTTP");
this.__request__.onreadystatechange = function(){
for(var i=0;i<props.length;i++){
try{
self[props[i]] = self.__request__[props[i]]
}catch(e){
}
}
self.onreadystatechange()
if(self.readyState == 4) self.onload();
}
this.onreadystatechange = function(){};
},
setInterval : function(func, interval) {
func(); // quickly f*ckin hack
},
clearInterval : function(timer) {
},
setTimeout : function(func, interval) {
func(); // quickly f*ckin hack
},
clearTimeout : function(timer) {
}
};
var methods = "open','abort','send','setRequestHeader','getResponseHeader','getAllResponseHeaders".split("','");
var make_method = function(name){
window.XMLHttpRequest.prototype[name] = function(){
var params = new Array(arguments.length);
for(var i=0;i<params.length;i++) params[i] = "_"+i;
return Function(
params.join(","),
["return this.__request__.",name,"(",params.join(","),")"].join("")
).apply(this,arguments);
}
};
for (var i=0;i<methods.length;i++) make_method(methods[i]);
for (var n in window) target[n] = window[n];
})(this);
function print(msg) {
WScript.StdOut.WriteLine(String(msg));
}
function require(source, target) {
target = target||this;
var fso = new ActiveXObject('Scripting.FileSystemObject');
var stm = fso.OpenTextFile(source, 1, false, -2);
var text = stm.ReadAll();
stm.Close();
eval(text, target);
for (var n in window) if (typeof target[n] === 'undefined') target[n] = window[n];
}
// }}}
require("jquery-latest.js");
$.each([1,2,3], function(index, item) {
print("foo" + item);
});
$.ajax({
type: "GET",
url: "http://www.google.co.jp/",
async: false,
success: function(data) {
print(data);
}
});
setTimeoutとかsetIntervalはf*ckingはhackなので$.get(非同期)は動きません。直す余地ありです。あと、XMLHttpRequestのbindはmalaさんのをパクってます。