2009/01/21


このサイトでは、jQuery Lightbox Plugin は"balupton edition"を入れているのですが、jQueryのバージョンを1.3に上げた途端、エラーが出る様になってしまいました。
調べた所、jQuery1.3ではSizzleという新しいセレクタが採用されており、以下の様な属性フィルタが動かない事が分かりました。
$('[@rel*=foo]')
さらに調べた所、どうやら"@"を付けている事自体が間違っているらしく"@"を取って $('[rel*=foo]')
としてやれば動く様になりました。なぜオリジナルの"@"付きのまま動いていたのかは分かりませんが...
本体への反映は以下
--- jquery.lightbox.js.orig 2008-09-12 02:46:50.000000000 +0900
+++ jquery.lightbox.js  2009-01-21 21:15:37.312500000 +0900
@@ -827,7 +827,7 @@
            var groups_n = 0;
            var orig_rel = this.rel;
            // Create the groups
-           $.each($('[@rel*='+orig_rel+']'), function(index, obj){
+           $.each($('[rel*='+orig_rel+']'), function(index, obj){
                // Get the group
                var rel = $(obj).attr('rel');
                // Are we really a group
ま、balupton edition使ってる人少ないかも知れませんが...
Posted at by



2009/01/14


追記
事情が変わった!(髭男爵)
変わってなかった...orz
詳細は下記。

おもしろい。
static - 素人がプログラミングを勉強するブログ
var counter = function () {
  var static = /(^o^)/;
  return ('i' in static)? ++static.i:
    static.i = 0;
};

console.log(counter()); // 0
console.log(counter()); // 1
console.log(counter()); // 2
console.log(counter()); // 3
http://d.hatena.ne.jp/javascripter/20090113/1231863436
正規表現リテラルがコンパイル時に生成され、静的保持される特性を利用したカウンタ。

でも使わない。気持ちワルイ!苦笑
皆、思いつくだろうけど私はやっぱりこう書く。
var counter = (function() {
  var static = 0;
  return function() {return static++};
})();

ちなみにベンチを取ってみた。
if (typeof console == 'undefined') console = {log:print};

var counter1 = function () {
  var static = /(^o^)/;
  return ('i' in static)? ++static.i:
    static.i = 0;
};

var counter2 = (function() {
  var static = 0;
  return function() {return static++};
})();

var start;
start = new Date().getTime();
for(var n = 0; n < 10000000; n++) counter1();
console.log(new Date().getTime() - start)

start = new Date().getTime();
for(var n = 0; n < 10000000; n++) counter2();
console.log(new Date().getTime() - start)
Windows XP、P4 3GHz CPU、1G Mem。

tracemonkey : JavaScript-C 1.8.0 pre-release 1 2007-10-03
6515
5500

v8 : V8 version 0.3.4 (internal)
1558
383

ま、やっぱりね...というところ。
結論
V8はえーーー!

追記 os0xさんから
var counter1 = function () { var static = /(^o^)/; return ++static.i || (static.i=0); }; こうすれば差は縮まる http://la.ma.la/blog/diary_200705301141.htm
とブックマークコメントを貰った。
counter3としてベンチに追加した所、結果が変わった
if (typeof console == 'undefined'{
  if (typeof print == 'function') console = {log:print};
  else if (typeof WScript != 'undefined') console = {log:function(s){WScript.StdOut.WriteLine(s)}};
  else console = {log:alert};
}

var counter1 = function () {
  var static = /(^o^)/;
  return ('i' in static)? ++static.i:
    static.i = 0;
};

var counter2 = (function() {
  var static = 0;
  return function() {return static++};
})();

var counter3 = function () {
  var static = /(^o^)/; return ++static.i || (static.i=0);
};

var start;
start = new Date().getTime();
for(var n = 0; n < 10000000; n++) counter1();
console.log("counter1:" + (new Date().getTime() - start))

start = new Date().getTime();
for(var n = 0; n < 10000000; n++) counter2();
console.log("counter2:" + (new Date().getTime() - start))

start = new Date().getTime();
for(var n = 0; n < 10000000; n++) counter3();
console.log("counter3:" + (new Date().getTime() - start))
さらにベンチにwindows scripting hostも足してみた。

tracemonkey : JavaScript-C 1.8.0 pre-release 1 2007-10-03
counter1:1624
counter2:381
counter3:529

v8 : V8 version 0.3.4 (internal)
counter1:1610
counter2:403
counter3:665

cscript : Microsoft (R) Windows Script Host Version 5.6
counter1:107282
counter3:44016
counter2:51297

おぉぉぉぉぉぉぉぉぉぉ!!!!なんと
正規表現オブジェクトの方が速いではないか!!!
詳細はos0xさんか何方かが書いてくれるとして...
失礼しました!!!
上の結果が正しいです。

結論
windows scripting hostおせーーー!

Posted at by



2008/09/11


ちょっと訳あって、WScriptからjQueryを呼び出す必要があり(嘘です)作ってみました。

これを使うと $.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 windowif (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さんのをパクってます。
Posted at by