<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Vantage Point of Queens &#187; JavaScript</title>
	<atom:link href="http://blog.nydd.org/topic/tech/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nydd.org</link>
	<description>Art, Hack and Rock'n Roll</description>
	<lastBuildDate>Wed, 16 Jun 2010 13:59:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JavaScript code review 000</title>
		<link>http://blog.nydd.org/2009/08/javascript-code-review-000/</link>
		<comments>http://blog.nydd.org/2009/08/javascript-code-review-000/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 03:44:27 +0000</pubDate>
		<dc:creator>beatak</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.nydd.org/?p=280</guid>
		<description><![CDATA[				今日は指向を変えて、JavaScript の code review をしてみたいと思います。DOM の操作をする以下のような DOM ノードとスクリプトがあるとします。
				&#60;div class="description expandTo_500 canToggle"&#62;...&#60;/div&#62;
&#60;script type="text/javascript"&#62;
var someFunction = function (elm) {
  var classes = elm.className.split(' ');
  for( var i in classes )
    if( /^expandTo_[0-9]*/.test( classes[i] ) )
      var lim_char = Number( classes[i].split('_')[1] );
  ...
};
&#60;/script&#62;
				ぱっと見て、何をするかまぁだいたいわかると思うんですが、この someFunction が実行されると、引数として受け取った element を、その [...]]]></description>
			<content:encoded><![CDATA[				<p>今日は指向を変えて、JavaScript の code review をしてみたいと思います。DOM の操作をする以下のような DOM ノードとスクリプトがあるとします。</p>
				<pre><code class="prettyprint">&lt;div class="description expandTo_500 canToggle"&gt;...&lt;/div&gt;
&lt;script type="text/javascript"&gt;
var someFunction = function (elm) {
  var classes = elm.className.split(' ');
  for( var i in classes )
    if( /^expandTo_[0-9]*/.test( classes[i] ) )
      var lim_char = Number( classes[i].split('_')[1] );
  ...
};
&lt;/script&gt;</code></pre>
				<p>ぱっと見て、何をするかまぁだいたいわかると思うんですが、この someFunction が実行されると、引数として受け取った element を、その class にある一定の数字を解析して、それによって何かの処理をしたい、ということだと思います。</p>
				<p>問題としたいのは以下の 4点あります。</p>
				<ul>
				<li>curly braces の欠如</li>
				<li>array の 列挙</li>
				<li>Number Objectの使用</li>
				<li>正規表現を有効につかっていない</li>
				</ul>
				<p>では順番に見ていきましょう。</p>
				<h4>curly braces の欠如</h4>
				<p><a href="http://www.flickr.com/photos/beatak/3328026346/" title="JavaScript: The Good Parts by Douglas Crockford by beatak, on Flickr" style="display: block; float:left; margin: 0 7px 7px 0;"><img src="http://farm4.static.flickr.com/3377/3328026346_6f640b60a4_m.jpg" width="240" height="201" alt="JavaScript: The Good Parts by Douglas Crockford" /></a>文法がそれを許している限り、これは好みの問題だ、という見方もあるんですが、<a href="http://www.crockford.com/javascript/">Douglas Crockford</a> によれば &#8220;Style isn&#8217;t subjective&#8221; だそうです。僕もそう思います。Curly braces はいかなる状況でも、省略すべきではないです。</p>
				<h4 style="clear:both;">array の 列挙</h4>
				<p>array 型の内容を列挙する時、JavaScript では、２つの方法があります。</p>
				<pre><code class="prettyprint">var arr1 = [0, 1, 2, 3, 4];
for (var i = 0, len = arr1.length; i &lt; len; ++i) {
  console.log(arr1[i]);
}

var arr2 = [0, 1, 2, 3, 4];
for (var j in arr2) {
  console.log(arr2[j]);
}</code></pre>
				<p> 上記の二つの for ループは、基本的に同じことを目的としてしていますし、多くの場合は同じ結果をもたらすと思いますが、後者は違う結果をもたらす可能性があります。for の中で使用される in 演算子はもともと object のプロパティを列挙する為にあって、array の列挙の為ではありません。例えば <code class="prettyprint">Array.prototype.foo = '99';</code> という文がアプリケーションのどこかにあると、それだけで違う結果をもたらします。Crockford氏の <a href="http://www.jslint.com/">jslint</a> を使うと、for (&#8230;in&#8230;) は object の列挙の時ですら、 hasOwnProperty を一緒に用いないと、警告が出ます。</p>
				<h4>Number Object の使用</h4>
				<p>number型、boolean型、string型、には、wrapper クラスが存在するのですが、これを使う十分な理由、というのは僕には考えられません。前にも一度書きましたが、ポインタの比較をしたい時（というのがもしあれば、ですが）に、確かにこれらを使うことはできますが…ここでしているようなことの為なら parseInt で十分でしょう。</p>
				<h4>正規表現を有効につかっていない</h4>
				<p>さて最後に、文字列から数字を取り出すのに、split を使うのはもったいないです。せっかく正規表現で確認しているわけですから、一緒に切り出し作業もしてもらいましょう。</p>
				<p>というわけで、書き直したコードを以下に。</p>
				<pre><code class="prettyprint">
var someFunction = function (elm) {
  var classes = elm.className.split(' ');
  var matches;
  var regex = /expandTo_(\d+)/;
  for (var i = 0, len = classes.length; i &lt; len; ++i) {
    matches = classes[i].match(regex)
    if (matches) {
      var lim_char = parseInt(matches[1]);
    }
  ...
};</code></pre>
				<p>正規表現の一節以外は、ほとんど Douglas Crockford の受け売りになってしまいました。この本を読むと、Crockford氏の JavaScript に対する考え方を理解できると思います。（そして Java のような JavaScript を書くことになると思いますが…まぁそれはまた別の機会に。）</p>
				<p><iframe src="http://rcm-jp.amazon.co.jp/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=0000FF&#038;t=grfdesign-22&#038;o=9&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=1X69VDGQCMF7Z30FM082&#038;asins=4873113911" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nydd.org/2009/08/javascript-code-review-000/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello World to Meetup.Tweener</title>
		<link>http://blog.nydd.org/2009/08/hello-world-to-meetup-tweener-ja/</link>
		<comments>http://blog.nydd.org/2009/08/hello-world-to-meetup-tweener-ja/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 05:04:38 +0000</pubDate>
		<dc:creator>beatak</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[meetup.tweener]]></category>
		<category><![CDATA[japanese]]></category>

		<guid isPermaLink="false">http://blog.nydd.org/?p=271</guid>
		<description><![CDATA[				今更、Hello World, という感じでもないんですが、Meetup.Tweener の解説記事を書いていこうと思います。
				Meetup.Tweener は僕が Open Source として開発している JavaScript のライブラリで、HTML + JavaScript の環境で非常に簡単にアニメーションを作ることができます。もし Flash での開発経験があれば、Tweener という Library は絶対聞いたことがあると思うのですが、Original の Tweener と API 互換性を持たせつつ、JavaScript 用に最適化をしています。
				今やどのメジャー JavaScript ライブラリもアニメーション機能があるというのになんでいまさらアニメーションライブラリ？と思われるかもしれません。Meetup.Tweener の利点は
				
				依存性は低く、（理論上では）どのメジャーライブラリとも共存できる
				長い間 Flash で培われた API
				Meetup での実用実績
				
				(1) に関して、今のところ対応しているのは jQuery と MochiKit だけなんですが、Prototype.js, MooTools, YUI, Dojo には対応する準備があります。(2) に関して、HTML5 が台頭してくるにあたって、多くの Flash 製作者が JavaScript に流れてくることが予想されます（楽観的）。彼らにとってなれしたしんできた syntax が使えるのはとても大きな資産になることでしょう。また、アニメーションをメジャーライブラリに頼らないことで、突然のコードベース変更にも強いでしょう。
				このライブラリは Google Adplanner によれば 6M の Unique Visitor [...]]]></description>
			<content:encoded><![CDATA[				<p>今更、Hello World, という感じでもないんですが、<a href="http://github.com/beatak/meetup.tweener/">Meetup.Tweener</a> の解説記事を書いていこうと思います。</p>
				<p>Meetup.Tweener は僕が Open Source として開発している JavaScript のライブラリで、HTML + JavaScript の環境で非常に簡単にアニメーションを作ることができます。もし Flash での開発経験があれば、<a href="http://code.google.com/p/tweener/">Tweener</a> という Library は絶対聞いたことがあると思うのですが、Original の Tweener と API 互換性を持たせつつ、JavaScript 用に最適化をしています。</p>
				<p>今やどのメジャー JavaScript ライブラリもアニメーション機能があるというのになんでいまさらアニメーションライブラリ？と思われるかもしれません。Meetup.Tweener の利点は</p>
				<ol>
				<li>依存性は低く、（理論上では）どのメジャーライブラリとも共存できる</li>
				<li>長い間 Flash で培われた API</li>
				<li>Meetup での実用実績</li>
				</ol>
				<p>(1) に関して、今のところ対応しているのは jQuery と MochiKit だけなんですが、Prototype.js, MooTools, YUI, Dojo には対応する準備があります。(2) に関して、HTML5 が台頭してくるにあたって、多くの Flash 製作者が JavaScript に流れてくることが予想されます（楽観的）。彼らにとってなれしたしんできた syntax が使えるのはとても大きな資産になることでしょう。また、アニメーションをメジャーライブラリに頼らないことで、突然のコードベース変更にも強いでしょう。</p>
				<p>このライブラリは <a href="https://www.google.com/adplanner/planning/site_profile#siteDetails?identifier=meetup.com&#038;lp=true">Google Adplanner によれば 6M の Unique Visitor をほこる Meetup.com</a> で運用の実績があります。実地で使われているものですから、問題があれば対処は素早く行われます。</p>
				<p>開発は <a href="http://github.com/beatak/meetup.tweener/">Github 上の meetup.tweener</a> レポジトリにて行われていて、<a href="http://beatak.github.com/meetup.tweener/">ドキュメントも Github 上</a>にあります。</p>
				<p>開発にあたって、Yuichi Tateno (id:secondlife) さんの <a href="http://hotchpotch.github.com/javascripts/JSTweener.js">JSTweener</a> を参考にさせていただきました。ありがとうございます。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nydd.org/2009/08/hello-world-to-meetup-tweener-ja/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pseudo 3D by canvas2D</title>
		<link>http://blog.nydd.org/2009/08/pseudo-3d-by-canvas2d/</link>
		<comments>http://blog.nydd.org/2009/08/pseudo-3d-by-canvas2d/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 02:25:51 +0000</pubDate>
		<dc:creator>beatak</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[english]]></category>

		<guid isPermaLink="false">http://blog.nydd.org/?p=258</guid>
		<description><![CDATA[				Today, I had a Hack-a-thon day at my work.  Basically, no meeting, just do whatever you wanna do.  It should be related to the work, but it doesn&#8217;t have to (am I right?).  So I have been thinking that I wanted work on something 3D by using canvas and my Meetup.Tweener.  [...]]]></description>
			<content:encoded><![CDATA[				<p>Today, I had a Hack-a-thon day at my work.  Basically, no meeting, just do whatever you wanna do.  It should be related to the work, but it doesn&#8217;t have to (am I right?).  So I have been thinking that I wanted work on something 3D by using canvas and my <a href="http://github.com/beatak/meetup.tweener/">Meetup.Tweener</a>.  I read lots of articles (which I have done before as well..), and gosh, I forgot so much about matrix transformation.  But anyway, let me show you what I did.  It&#8217;s only half done but it&#8217;s still sort of interesting how much you can do with canvas.</p>
				<p><a href="http://archive.nydd.org/2009/aug/3d_by_canvas2d/">Fliping picture</a></p>
				<p>Click on picture, it will flip around.</p>
				<p>This is even worse than CSS transformation because it only works for x-axis scaling as opposed to, CSS transformation, you can do 3d, at least more 3D-ish, flipping animation.  BUT ANYWAY, this just fire on my heart to learn 3D again. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nydd.org/2009/08/pseudo-3d-by-canvas2d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visitor and Iterator pattern in JavaScript</title>
		<link>http://blog.nydd.org/2009/06/visitor-and-iterator-pattern-in-javascript/</link>
		<comments>http://blog.nydd.org/2009/06/visitor-and-iterator-pattern-in-javascript/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 05:17:02 +0000</pubDate>
		<dc:creator>beatak</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[japanese]]></category>

		<guid isPermaLink="false">http://blog.nydd.org/?p=248</guid>
		<description><![CDATA[				最近また実験的なアプリを JavaScript で書いているんですが、node walker を書く必要にかられ、デザインパターン入門をまた開いてみました。以下のページを開いて、Firebug の console で、例えば window.d = new DOMNodeDest(document.body); d.accept(new Visitor()); などとすれば、各ノードを列挙してくれます。
				Viistor Pattern
				実際、頭を悩ましたのは、Visitor パターンというより、むしろ Iterator パターンでした。結構面白いと思うんですけど、どうでしょう？
				
Iterator = function (obj) {
  var i, chld, len, pub, mth,
      result  = {},
      BIND    = Iterator.bind;
  if (obj instanceof Array) [...]]]></description>
			<content:encoded><![CDATA[				<p>最近また実験的なアプリを JavaScript で書いているんですが、node walker を書く必要にかられ、デザインパターン入門をまた開いてみました。以下のページを開いて、Firebug の console で、例えば <code class="prettyprint">window.d = new DOMNodeDest(document.body); d.accept(new Visitor());</code> などとすれば、各ノードを列挙してくれます。</p>
				<p><a href="http://archive.nydd.org/2009/jun/visitor_pattern/">Viistor Pattern</a></p>
				<p>実際、頭を悩ましたのは、Visitor パターンというより、むしろ Iterator パターンでした。結構面白いと思うんですけど、どうでしょう？</p>
				<pre class="prettyprint">
Iterator = function (obj) {
  var i, chld, len, pub, mth,
      result  = {},
      BIND    = Iterator.bind;
  if (obj instanceof Array) {
    this.children = obj;
  }
  else if (typeof(obj) === 'object' &#038;&#038; obj !== null) {
    this.children = [];
    chld = this.children;
    for (i in obj) {
      if (obj.hasOwnProperty(i)) {
        chld[chld.length] = obj[i];
      }
    }
  }

  pub = Iterator.publics;
  for (i = 0, len = pub.length; i < len; ++i) {
    mth = pub[i];
    result[mth] = BIND(this[mth], this);
  }
  return result;
};

Iterator.publics = ['next', 'hasNext', 'rewind'];
Iterator.prototype.index    = -1;
Iterator.prototype.children = null;

Iterator.prototype.next = function () {
  if (this.children === null) {
    return null;
  }
  var CHLD    = this.children,
      len     = CHLD.length,
      result  = null;
  ++this.index;
  if (len !== 0 &#038;&#038; this.index < len) {
    result = CHLD[this.index];
  }
  return result;
};

Iterator.prototype.hasNext = function () {
  if (this.children === null) {
    return false;
  }
  var result  = false,
      len     = this.children.length;
  if (len !== 0 &#038;&#038; this.index < (len - 1)) {
    result = true;
  }
  return result;
};

Iterator.prototype.rewind = function () {
  this.index = -1;
  var it,
      i     = 0,
      CHLD  = this.children,
      len   = CHLD.length;
  if (len) {
    for (;i < len; ++i) {
      it = CHLD[i].iterator;
      if (it) {
        it.rewind();
      }
    }
  }
};

Iterator.bind = function (func, context) {
  return function () {
    return func.apply(context, arguments);
  };
};
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.nydd.org/2009/06/visitor-and-iterator-pattern-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Page Speed and Google&#8217;s JavaScript</title>
		<link>http://blog.nydd.org/2009/06/google-page-speed-and-googles-javascript/</link>
		<comments>http://blog.nydd.org/2009/06/google-page-speed-and-googles-javascript/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 14:58:10 +0000</pubDate>
		<dc:creator>beatak</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[english]]></category>

		<guid isPermaLink="false">http://blog.nydd.org/?p=241</guid>
		<description><![CDATA[				
				Google recently introduced a Firebug extension, called Google Page Speed.  Simply, it&#8217;s a Google version of YSlow.  I heard the author of YSlow, Steve Souders moved to Google, so I thought it&#8217;s a bit awkward corporate feeling but he himself said that he is not involved with this project.  But even so, [...]]]></description>
			<content:encoded><![CDATA[				<p><a href="http://www.flickr.com/photos/beatak/3603898082/" title="page speed by beatak, on Flickr"><img src="http://farm3.static.flickr.com/2452/3603898082_2661e4fef0.jpg" width="500" height="384" alt="page speed" /></a></p>
				<p><a href="http://google-code-updates.blogspot.com/2009/06/introducing-page-speed.html">Google recently introduced a Firebug extension</a>, called <a href="http://code.google.com/p/page-speed/">Google Page Speed</a>.  Simply, it&#8217;s a Google version of YSlow.  I heard the author of YSlow, <a href="http://stevesouders.com/">Steve Souders</a> moved to Google, so I thought it&#8217;s a bit awkward corporate feeling but <a href="http://www.stevesouders.com/blog/2009/06/03/using-iframes-sparingly/#comment-637">he himself said that he is not involved with this project</a>.  But even so, Yahoo has a hard time anyway.</p>
				<p>As other Google&#8217;s products, Google Page Speed is also open source project, hosted on Google Code.  So I was curious to browse their code.  I don&#8217;t really read anything but JavaScript, and I found <a href="<a href="http://code.google.com/p/page-speed/source/browse/trunk/src/js/closure/base.js">very familiar code on their internal library: /src/js/closure/base.js</a>.</p>
				<p>Do you remember when I talked about <a href="http://blog.nydd.org/2009/04/29/dear-google-stop-contaminating-standard-global-objects-in-javascript/">Google&#8217;s bad contamination on google_service.js before</a>?</p>
				<p>The problem is fixed now but you can find very identical code to the code I quoted on the post (well, it&#8217;s obfuscated, but you can imagine).  I have strong feeling that the one I accused, &#8220;google_service.js&#8221; contains the google closure, or maybe it was just a google closure.</p>
				<p>And I also found a project named <a href="http://code.google.com/p/google-closure/">Google Closure</a>.  It&#8217;s empty so far, and its founder is&#8230; ExplorerCanvas guy!</p>
				<p>I originally had a very difficult feeling about so-called Google Closure, because it potentially breaks lots of other library as I stated on the post.  But if it&#8217;s open sourced and I will definitely be more interested in.  What it does so far is very&#8230; engineering smart.  Somethng you must need on JavaScript.  It comes with lots of lots of comments, and its abstraction level is very clear.  Maybe I should do drill down series of blog post about it? <img src='http://blog.nydd.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nydd.org/2009/06/google-page-speed-and-googles-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Timer Performance in Browsers</title>
		<link>http://blog.nydd.org/2009/04/timer-performance-in-browsers/</link>
		<comments>http://blog.nydd.org/2009/04/timer-performance-in-browsers/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 16:45:25 +0000</pubDate>
		<dc:creator>beatak</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[english]]></category>

		<guid isPermaLink="false">http://blog.nydd.org/?p=224</guid>
		<description><![CDATA[				 courtesy of Telstar Logistics / Todd Lappin
				
				After finishing Meetup.Tweener, I started to do lots of animation by JavaScript.  In JavaScript, all animation happens by built-in timer.  You can call either window.setTimeout or window.setInterval.  So it&#8217;s all about how accurate the timer is fired, if you want to do precise animation.
				I guess [...]]]></description>
			<content:encoded><![CDATA[				<p><a href="http://www.flickr.com/photos/telstar/3303367343/" style="padding-right:10px;"><img alt="" src="http://farm4.static.flickr.com/3538/3303367343_b3ee5458f2_m.jpg" title="Kodak Timerr" width="240" height="180" align="left" /></a> courtesy of <a href="http://www.flickr.com/people/telstar/">Telstar Logistics / Todd Lappin</a><br />
				<br style="clear:both;" /></p>
				<p>After finishing Meetup.Tweener, I started to do lots of animation by JavaScript.  In JavaScript, all animation happens by built-in timer.  You can call either <code>window.setTimeout</code> or <code>window.setInterval</code>.  So it&#8217;s all about how accurate the timer is fired, if you want to do precise animation.</p>
				<p>I guess I have read somewhere before, but I just made up tiny JavaScript page here.</p>
				<p><a href="http://archive.nydd.org/2009/apr/timercheck/">Timer Check @ archive.nydd.org</a></p>
				<p>My observation:</p>
				<ul>
				<li>Firefox 3 is not that accurate.  The interval tends to be much more wobbling than others.  My Firefox is significantly slow..  Maybe because theme (Gray Modern 2), Firebug or something else.</li>
				<li>Safari is not bad.  Sometimes, it does GC?  it takes 10 times more than usual.  But mostly, the performance is constant.</li>
				<li>Google Chrome is supreme.  It has the best accuracy.  If I cut counter update, I guess it can do much more.</li>
				<li>IE 6 is actually very good too.   It never hits less than certain point, but the interval is very steady.</li>
				<li>Opera is also not too bad too.  I don&#8217;t understand why, but it sometimes hits double time, very periodically.</li>
				<li>IE7, IE8, I will take a look at it soon.</li>
				</ul>
				<p>Try the page!  Questions and comments are all welcomed,  And let me know if you find something interesting.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nydd.org/2009/04/timer-performance-in-browsers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dear Google: Stop contaminating Standard Global Objects in JavaScript</title>
		<link>http://blog.nydd.org/2009/04/dear-google-stop-contaminating-standard-global-objects-in-javascript/</link>
		<comments>http://blog.nydd.org/2009/04/dear-google-stop-contaminating-standard-global-objects-in-javascript/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 16:55:25 +0000</pubDate>
		<dc:creator>beatak</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[english]]></category>

		<guid isPermaLink="false">http://blog.nydd.org/?p=219</guid>
		<description><![CDATA[				So, I was at work in this morning, tried to start to work on the task I&#8217;ve been working on a while.  I looked up my task note (wiki) and run some code (on browser, naturally, I&#8217;m a JavaScript geek), then I realized that it stopped because of unfamiliar errors.  Wait.  It [...]]]></description>
			<content:encoded><![CDATA[				<p>So, I was at work in this morning, tried to start to work on the task I&#8217;ve been working on a while.  I looked up my task note (wiki) and run some code (on browser, naturally, I&#8217;m a JavaScript geek), then I realized that it stopped because of unfamiliar errors.  Wait.  It was working last night.  Then I ran some debuggers, then I found weird functions on each function.  I asked people on the internal IRC channel. And I figured this:</p>
				<p><a href="http://partner.googleadservices.com/gampad/google_service.js">http://partner.googleadservices.com/gampad/google_service.js</a></p>
				<p>Let me just quote its high light here:</p>
				<pre class="prettyprint">
  if (t.MODIFY_FUNCTION_PROTOTYPES = f) {
    Function.prototype.bind = function(a) {
      if (arguments.length > 1) {
        var b = Array.prototype.slice.call(arguments, 1);
        b.unshift(this, a);
        return t.bind.apply(c, b)
      } else return t.bind(this, a)
    };
    Function.prototype.partial = function() {
      var a = Array.prototype.slice.call(arguments);
      a.unshift(this, c);
      return t.bind.apply(c, a)
    };
    Function.prototype.inherits = function(a) {
      t.inherits(this, a)
    };
    Function.prototype.mixin = function(a) {
      t.mixin(this.prototype, a)
    }
  };
</pre>
				<p>It looks even different from what I saw at the office, actually.  but I believe it&#8217;s the very same result since variable <code>f</code> is actually assigned for &#8220;true&#8221; in the very beginning.</p>
				<p>And I googled a while and found this:</p>
				<p><a href="http://www.google.com/support/forum/p/Google+Ad+Manager/thread?tid=3967346305c93136">Question: google_service.js conflicts with prototype.js</a></p>
				<p>Good job jimthoburn!  Google usually doesn&#8217;t listen to outside voice.</p>
				<p>I really hope that Google will stop doing this very very soon.  I mean like tomorrow.  It&#8217;s not only about Prototype.js, in face I don&#8217;t use Prototype.js at work.  But IT IS REALLY BAD practice to contaminate Standard Global Objects in JavaScript.  Please please do not do this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nydd.org/2009/04/dear-google-stop-contaminating-standard-global-objects-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Meetup.Tweener (0.5.1)</title>
		<link>http://blog.nydd.org/2009/04/meetuptweener-0_5_1-ja/</link>
		<comments>http://blog.nydd.org/2009/04/meetuptweener-0_5_1-ja/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 09:13:02 +0000</pubDate>
		<dc:creator>beatak</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[japanese]]></category>

		<guid isPermaLink="false">http://blog.nydd.org/?p=216</guid>
		<description><![CDATA[				まだ正式なアナウンスなどをしていないんですが、Github 上で Meetup.Tweener の開発を始めました。サンプルなどを充実させられたらと思っています。コメントは NaturalDocs でパース可能な状態になっていますので、ドキュメントに必要な方は NaturalDocs を使ってみてください。NaturalDocs のスタイル化が出来たらそれも package に含めようと思っています。
]]></description>
			<content:encoded><![CDATA[				<p>まだ正式なアナウンスなどをしていないんですが、<a href="http://github.com/beatak/meetup.tweener">Github 上で Meetup.Tweener</a> の開発を始めました。サンプルなどを充実させられたらと思っています。コメントは NaturalDocs でパース可能な状態になっていますので、ドキュメントに必要な方は NaturalDocs を使ってみてください。NaturalDocs のスタイル化が出来たらそれも package に含めようと思っています。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nydd.org/2009/04/meetuptweener-0_5_1-ja/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Meetup.Tweener (0.5.1)</title>
		<link>http://blog.nydd.org/2009/04/meetuptweener-0_5_1-en/</link>
		<comments>http://blog.nydd.org/2009/04/meetuptweener-0_5_1-en/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 09:09:17 +0000</pubDate>
		<dc:creator>beatak</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tech]]></category>
		<category><![CDATA[english]]></category>

		<guid isPermaLink="false">http://blog.nydd.org/?p=213</guid>
		<description><![CDATA[				Not really announcing yet, but I started a repository Meetup.Tweener on Github.  Check it out, if you&#8217;re interested in.  I will write more samples soon.  Comments are all written in NaturalDocs compatible style in its source code.  Once I finish styling for it, I will include that in the repository, which, [...]]]></description>
			<content:encoded><![CDATA[				<p>Not really announcing yet, but I started a repository <a href="http://github.com/beatak/meetup.tweener">Meetup.Tweener on Github</a>.  Check it out, if you&#8217;re interested in.  I will write more samples soon.  Comments are all written in NaturalDocs compatible style in its source code.  Once I finish styling for it, I will include that in the repository, which, I wish, will happen soon&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nydd.org/2009/04/meetuptweener-0_5_1-en/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Safari バグ: TD エレメントの間違った offsetTop 値</title>
		<link>http://blog.nydd.org/2009/03/safari-%e3%83%90%e3%82%b0-td-%e3%82%a8%e3%83%ac%e3%83%a1%e3%83%b3%e3%83%88%e3%81%ae%e9%96%93%e9%81%95%e3%81%a3%e3%81%9f-offsettop-%e5%80%a4/</link>
		<comments>http://blog.nydd.org/2009/03/safari-%e3%83%90%e3%82%b0-td-%e3%82%a8%e3%83%ac%e3%83%a1%e3%83%b3%e3%83%88%e3%81%ae%e9%96%93%e9%81%95%e3%81%a3%e3%81%9f-offsettop-%e5%80%a4/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 05:34:52 +0000</pubDate>
		<dc:creator>beatak</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[japanese]]></category>

		<guid isPermaLink="false">http://blog.nydd.org/?p=177</guid>
		<description><![CDATA[				# 追記: このバグは最新の開発版では修正されています。WebKit Bugzilla を参照のこと→ WebKit Bugzilla 19094. Nightly でも既に修正されているみたいですね。もしこれに関してハックをしたなら（つまり僕のことですが）、以下のようなもう一つ、ハックが必要です。
				
var webkit = indow.navigator.userAgent.match(/WebKit\/([0-9]{3})/);
if (webkit &#038;&#038; parseInt(webkit[1]) < 528) {
...
}

				
				JavaScript ライブラリの多くは、HTML エレメントの（ページ上での）ピクセル位置（絶対座標）を返すメソッドを備えています。jQuery の jQuery.offset() しかり、MochiKit の MochiKit.Style.getElementPosition() しかり、MooTools の Element.getPosition() 等々… ほとんどの場合これらはうまく動くのですが、今日動かないケースを確認し、おそらく Safari のバグだと思うのでここに報告しておきます。
				以下の条件が揃ったとき、ピクセル絶対座標を取得するメソッドは間違った値を返します。
				
				ブラウザは Safari
				取得しようとしているエレメントは TD (あるいは display:table-cell)
				CSS で vertical-align を top 以外の値 (middle or bottom) が設定されている
				
				次にこのケースの例を作りました。Safaribug: wrong offsetTop on TD. テーブルセルをクリックすると、アラートで、そのテーブルセルのピクセル座標を返します。Safari とその他のブラウザで開いてみてください。違いがあります。
				ではコードで解説します。以下は Google doctype project [...]]]></description>
			<content:encoded><![CDATA[				<p># <em>追記</em>: このバグは最新の開発版では修正されています。WebKit Bugzilla を参照のこと→ <a href="https://bugs.webkit.org/show_bug.cgi?id=19094">WebKit Bugzilla 19094</a>. Nightly でも既に修正されているみたいですね。もしこれに関してハックをしたなら（つまり僕のことですが）、以下のようなもう一つ、ハックが必要です。</p>
				<pre class="prettyprint">
var webkit = indow.navigator.userAgent.match(/WebKit\/([0-9]{3})/);
if (webkit &#038;&#038; parseInt(webkit[1]) < 528) {
...
}
</pre>
				<hr />
				<p>JavaScript ライブラリの多くは、HTML エレメントの（ページ上での）ピクセル位置（絶対座標）を返すメソッドを備えています。jQuery の <a href="http://docs.jquery.com/CSS/offset">jQuery.offset()</a> しかり、MochiKit の <a href="http://mochikit.com/doc/html/MochiKit/Style.html#fn-getelementposition">MochiKit.Style.getElementPosition()</a> しかり、MooTools の <a href="http://mootools.net/docs/Element/Element.Dimensions#Element:getPosition">Element.getPosition()</a> 等々… ほとんどの場合これらはうまく動くのですが、今日動かないケースを確認し、おそらく Safari のバグだと思うのでここに報告しておきます。</p>
				<p>以下の条件が揃ったとき、ピクセル絶対座標を取得するメソッドは間違った値を返します。</p>
				<ol>
				<li>ブラウザは Safari</li>
				<li>取得しようとしているエレメントは TD (あるいは display:table-cell)</li>
				<li>CSS で vertical-align を top 以外の値 (middle or bottom) が設定されている</li>
				</ol>
				<p>次にこのケースの例を作りました。<a href="http://archive.nydd.org/2009/mar/safaribug/">Safaribug: wrong offsetTop on TD</a>. テーブルセルをクリックすると、アラートで、そのテーブルセルのピクセル座標を返します。Safari とその他のブラウザで開いてみてください。違いがあります。</p>
				<p>ではコードで解説します。以下は <a href="http://code.google.com/p/doctype/">Google doctype project</a> で見つけた <a href="http://code.google.com/p/doctype/wiki/ArticlePageOffset">PageOffset: How to calculate the position of an element on the page (goog.style.getPageOffset)</a> を下にしています。オリジナルの PageOffset のコードは非常に細かく説明してあるので、一度読んで見ることをお勧めします。長くないし。</p>
				<pre class="prettyprint">
function getPageOffset(el) {
    var pos = {
        x: 0,
        y: 0
    };
    var viewportElement = document;
    if (el == viewportElement) {
        return pos;
    }

    var parent = null;
    var box;

    pos.x = el.offsetLeft;
    pos.y = el.offsetTop;

    parent = el.offsetParent;
    if (parent != el) {
        while (parent) {
            pos.x += parent.offsetLeft;
            pos.y += parent.offsetTop;
            parent = parent.offsetParent;
        }
    }

    if (el.style.position == 'absolute') {
        pos.y -= doc.body.offsetTop;
    }

    parent = el.offsetParent;
    while (parent &#038;&#038; parent != document.body) {
        pos.x -= parent.scrollLeft;
        parent = parent.offsetParent;
    }

    return pos;
};
</pre>
				<p>Safari では、指定したエレメントから、その相対目標（これを指定しなければ、document.body を相対目標とします。つまりページの絶対座標ですね。）まで、エレメントを上り詰めて、その間の offset を累積加算していきます。問題は、一番最初の <code>el.offsetTop</code> (15行目) で起こります。これは table cell で、padding/margin/border が設定されていませんから、0 であるべきなのですが、Safari は、子孫要素への offset を返しているようなんですね。</p>
				<p>どうにもいい方法が見つからなかったので、実際のアプリケーションではダーティハックを入れました<del datetime="2009-03-21T05:52:48+00:00">が、WebKit チームの早急な fix を望みます!!</del>。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nydd.org/2009/03/safari-%e3%83%90%e3%82%b0-td-%e3%82%a8%e3%83%ac%e3%83%a1%e3%83%b3%e3%83%88%e3%81%ae%e9%96%93%e9%81%95%e3%81%a3%e3%81%9f-offsettop-%e5%80%a4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
