<?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>あらかたは回帰、きまぐれは彷徨</title>
	<atom:link href="http://arakata-kimagure.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://arakata-kimagure.net</link>
	<description></description>
	<lastBuildDate>Sat, 08 Oct 2011 11:23:45 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>jQueryで要素が存在するか調べる方法</title>
		<link>http://arakata-kimagure.net/2011/10/08/jquery%e3%81%a7%e8%a6%81%e7%b4%a0%e3%81%8c%e5%ad%98%e5%9c%a8%e3%81%99%e3%82%8b%e3%81%8b%e8%aa%bf%e3%81%b9%e3%82%8b%e6%96%b9%e6%b3%95/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery%25e3%2581%25a7%25e8%25a6%2581%25e7%25b4%25a0%25e3%2581%258c%25e5%25ad%2598%25e5%259c%25a8%25e3%2581%2599%25e3%2582%258b%25e3%2581%258b%25e8%25aa%25bf%25e3%2581%25b9%25e3%2582%258b%25e6%2596%25b9%25e6%25b3%2595</link>
		<comments>http://arakata-kimagure.net/2011/10/08/jquery%e3%81%a7%e8%a6%81%e7%b4%a0%e3%81%8c%e5%ad%98%e5%9c%a8%e3%81%99%e3%82%8b%e3%81%8b%e8%aa%bf%e3%81%b9%e3%82%8b%e6%96%b9%e6%b3%95/#comments</comments>
		<pubDate>Sat, 08 Oct 2011 11:23:25 +0000</pubDate>
		<dc:creator>sjun</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://arakata-kimagure.net/?p=221</guid>
		<description><![CDATA[本当は書きたいネタが沢山たまっているのですが、そういうときに限って忙しいものですね。 小ネタですが、すぐ忘れてしまうので、メモ代わりにjQueryである要素が存在するか調べる方法を。 普通のobjectが存在するか調べる [...]]]></description>
			<content:encoded><![CDATA[<p>
本当は書きたいネタが沢山たまっているのですが、そういうときに限って忙しいものですね。<br />
小ネタですが、すぐ忘れてしまうので、メモ代わりにjQueryである要素が存在するか調べる方法を。
</p>
<p>
普通のobjectが存在するか調べる時にこうすることが多いので、どうもこうやって書いてしまう癖があります&#8230;。</p>
<pre class="brush: jscript; title: ; notranslate">
if($('#foo')){
    //do something
}
</pre>
<p>でも、jQueryで要素があるか判定するのには、こうしないといけません。</p>
<pre class="brush: jscript; title: ; notranslate">
if ($('#myDiv).length) {
        // your code
}
</pre>
<blockquote><p>
<a href="http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx">Improve your jQuery &#8211; 25 excellent tips</a>
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://arakata-kimagure.net/2011/10/08/jquery%e3%81%a7%e8%a6%81%e7%b4%a0%e3%81%8c%e5%ad%98%e5%9c%a8%e3%81%99%e3%82%8b%e3%81%8b%e8%aa%bf%e3%81%b9%e3%82%8b%e6%96%b9%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Node.js で MySQL</title>
		<link>http://arakata-kimagure.net/2011/09/10/node-js-%e3%81%a7-mysql/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=node-js-%25e3%2581%25a7-mysql</link>
		<comments>http://arakata-kimagure.net/2011/09/10/node-js-%e3%81%a7-mysql/#comments</comments>
		<pubDate>Sat, 10 Sep 2011 14:53:09 +0000</pubDate>
		<dc:creator>sjun</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Node.js]]></category>

		<guid isPermaLink="false">http://arakata-kimagure.net/?p=209</guid>
		<description><![CDATA[Node.jsとMySQLをつなぐためのプラグインは数種類ある。 node-mysql — A node.js module implementing the MySQL protocol node-mysql-nati [...]]]></description>
			<content:encoded><![CDATA[<p>
Node.jsとMySQLをつなぐためのプラグインは数種類ある。
</p>
<ul>
<li><a href="https://github.com/felixge/node-mysql">node-mysql</a> — A node.js module implementing the MySQL protocol</li>
<li><a href="https://github.com/sidorares/nodejs-mysql-native">node-mysql-native</a> — Mysql client module for node.js, written in JavaScript. No other mysql runtime required.</li>
<li><a href="https://github.com/Sannis/node-mysql-libmysqlclient">node-mysql-libmysqlclient</a> — MySQL bindings for Node.js using libmysqlclient.</li>
<li><a href="https://github.com/Kijewski/node-mysql-pool">node-mysql-pool</a> — MySQL connection pool for node.js on top of Felix Geisendörfer&#8217;s MySQL client node-mysql.</li>
</ul>
<p>
今回は、<a href="https://github.com/felixge/node-mysql">node-mysql</a>を使う。node-界隈は、同じようなことをできる同じようなパッケージがわらわらあるので、よくわかんない時は、とりあえず一番活発なやつ使えば、まあ、よいと思う。笑</p>
<pre class="brush: bash; title: ; notranslate">
sudo npm install

npm install mysql
mysql@0.9.4 ./node_modules/mysql
└── hashish@0.0.4
</pre>
<p>まずは基本的な設定から</p>
<pre class="brush: jscript; title: ; notranslate">
var mysql = require('mysql');
var TEST_DATABASE = 'nodejs_mysql_test';
var TEST_TABLE = 'test';
var client = mysql.createClient({
  user: 'mysqluser',
  password: 'password',

  host: foo.bar

  database: sample

});
</pre>
<p>接続の設定は、createClientの引数に設定してやってもいいし、</p>
<pre class="brush: jscript; title: ; notranslate">

client.host = &quot;foo.bar&quot;;

client.database = &quot;sample&quot;;
</pre>
<p>みたいな感じに、メソッドでもいける。他にもあるけれど、詳細は、<a href="https://github.com/felixge/node-mysql">git/node-mysql</a>で。</p>
<p>queryを投げるには、cakePHPなどでやるように </p>
<pre class="brush: jscript; title: ; notranslate">

client.query('USE sample_table');
</pre>
<p>みたいにそのままSQL文を書いてやる。</p>
<pre class="brush: jscript; title: ; notranslate">
client.query(
  'INSERT INTO '+TEST_TABLE+' '+
  'SET title = ?, text = ?, created = ?',
  ['super cool', 'this is a nice text', '2010-08-16 10:00:23']
);
</pre>
<p>そのまま変数に突っ込む事も可能だけれど、サニタイズしないといけないので、?で項目を指定しておいて、二つ目の引数に値を配列にまとめて入力している。</p>
<blockquote>
<p>node-mysqlクライアントオブジェクトはこれ(質問に対して)を支援することのできるエスケープメソッドを持っています。自分でそれを呼び出すこともできるし、そのパラメータを受け入れるqueryの形式を使うこともできます。たとえば、</p>
<pre class="brush: jscript; title: ; notranslate">
client.query('SELECT id, user_name FROM user WHERE email=?',

    [req.body.login], ...
</pre>
<p>The node-mysql Client object has an escape method that can help with this. You can either call that manually, or use the form of query that accepts parameters. E.g:</p>
<pre class="brush: jscript; title: ; notranslate">
client.query('SELECT id, user_name FROM user WHERE email=?',

    [req.body.login], ...
</pre>
<p>http://stackoverflow.com/questions/5878266/using-mysql-with-nodejs-and-express-node-mysql</p>
</blockquote>
<p>たぶん&#8230;とは思ってて調べてなかったのだけれど、どうやらエスケープメソッドで、ちゃんとサニタイズしているらしい。</p>
<p>insertやupdateはこれだけでもよいのだが、selectの場合は結果を返す変数が欲しいので、１つ目でselect文、二つ目の引数にコールバック関数を指定してやる。</p>
<pre class="brush: jscript; title: ; notranslate">
client.query(
  'SELECT * FROM '+TEST_TABLE,
  function selectCb(err, results, fields) {
    if (err) {
      throw err;
    }

    console.log(results);
    console.log(fields);
//    client.end();
  }
);
</pre>
<p>
で、僕が使ったときにはまってしまったのはここのポイント</p>
<p>    client.end();</p>
<p>一度client.end()してしまうと、MySQLとの通信を終了してしまうので、それ以後全く通信できなくなる。end()メソッドをちゃんと理解してなかったのが悪いんだけど&#8230;
</p>
<blockquote>
<p>client.end([callback])<br />
接続を閉じるためにCOM_QUITパケットをスケジュールに組み込みます。コネクションの<del datetime="2011-09-10T14:59:01+00:00">華麗な</del>切断を試みる前に、すべての投げられたqueryが実行されます。<br />
Schedule a COM_QUIT packet for closing the connection. All currently queued queries will still execute before the graceful termination of the connection is attempted.</p>
</blockquote>
<p>ちなみにこんなのもある。</p>
<blockquote>
<p>client.destroy([callback])<br />
クライエントに対し直ちに接続を切断させます。これは接続を切断する方法としてはあまり良い方法ではありません。きをつけて使ってください。<br />
Forces the client connection to be destroyed right away. This is not a nice way to terminate the connection, use with caution.</p>
</blockquote>
<p>
ので、何度も通信する必要があるものは、不用意にclient.end()してはいけない。</p>
]]></content:encoded>
			<wfw:commentRss>http://arakata-kimagure.net/2011/09/10/node-js-%e3%81%a7-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Socket.IOがwebsocket(hybi7, hybi10)に対応 + Websocket (Socket.IO)での通信が、アンチウイルスソフトに遮断されてしまう</title>
		<link>http://arakata-kimagure.net/2011/09/06/websocket-socket-io%e3%81%a7%e3%81%ae%e9%80%9a%e4%bf%a1%e3%81%8c%e3%80%81%e3%82%a2%e3%83%b3%e3%83%81%e3%82%a6%e3%82%a4%e3%83%ab%e3%82%b9%e3%82%bd%e3%83%95%e3%83%88%e3%81%ab%e9%81%ae%e6%96%ad/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=websocket-socket-io%25e3%2581%25a7%25e3%2581%25ae%25e9%2580%259a%25e4%25bf%25a1%25e3%2581%258c%25e3%2580%2581%25e3%2582%25a2%25e3%2583%25b3%25e3%2583%2581%25e3%2582%25a6%25e3%2582%25a4%25e3%2583%25ab%25e3%2582%25b9%25e3%2582%25bd%25e3%2583%2595%25e3%2583%2588%25e3%2581%25ab%25e9%2581%25ae%25e6%2596%25ad</link>
		<comments>http://arakata-kimagure.net/2011/09/06/websocket-socket-io%e3%81%a7%e3%81%ae%e9%80%9a%e4%bf%a1%e3%81%8c%e3%80%81%e3%82%a2%e3%83%b3%e3%83%81%e3%82%a6%e3%82%a4%e3%83%ab%e3%82%b9%e3%82%bd%e3%83%95%e3%83%88%e3%81%ab%e9%81%ae%e6%96%ad/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 15:27:10 +0000</pubDate>
		<dc:creator>sjun</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Socket.IO]]></category>

		<guid isPermaLink="false">http://arakata-kimagure.net/?p=188</guid>
		<description><![CDATA[一週間ほど前から、WebSocket(hybi7, hybi10)がSocket.IOでサポートされるようになりました。 Socket.IO 0.8.0 with support for Firefox6 WebSock [...]]]></description>
			<content:encoded><![CDATA[<p>
一週間ほど前から、WebSocket(hybi7, hybi10)がSocket.IOでサポートされるようになりました。
</p>
<blockquote><p>
Socket.IO 0.8.0 with support for Firefox6 WebSockets and Chrome betas.<br />
Server<br />
0.8.0 / 2011-08-28<br />
==================<br />
  * Added hybi7 support.<br />
  * Added hybi10 support. [einaros]<br />
(Socket.IO Official MLより一部省略)
</p></blockquote>
<p>
ChromiumのBlogやMozillaのDev Blogでも触れてますが、hybi7, hybi10で脆弱性に対応しています。
</p>
<blockquote>
<p>The WebSocket protocol specification is now largely stable, having solved previous <a href="http://www.ietf.org/mail-archive/web/hybi/current/msg04744.html">security concerns</a>.</p>
<p>Please upgrade your servers to ones which support HyBi 10.</p>
<p><a href=" http://blog.chromium.org/2011/08/new-websocket-protocol-secure-and.html"></p>
<p>http://blog.chromium.org/2011/08/new-websocket-protocol-secure-and.html</a></p>
</blockquote>
<blockquote><p>
WebSocket の実装を最新仕様に対応</p>
<p>Firefox 6 では仕様上のセキュリティ問題が修正済みの WebSocket (ietf-07) がサポートされましたが、Firefox 7 ではその後の仕様更新 (ietf-10) に対応しています。<br />
<a href="https://dev.mozilla.jp/2011/08/firefox7/">Firefox 7 の主な新機能を紹介します @ Mozilla Developer Street</a>
</p></blockquote>
<p>
Socket.IO@0.8.3に更新してみたところ、Websocketがどうしたことか動かない。firebugのコンソールを見てみると、&#8221;ws://hogehoge/への接続に失敗しました&#8221;なんたらと表示されている。しかも、Socket.IO 0.7xで動いていたxhr-pollingも動かないし、jsonp-pollingまで動かない。</p>
<p>公式のMLにもそんな話はのってないですし、最初はポートかなあとも思ったんですが、XHR-pollingは今まで問題なく動いてたので、おそらくローカルな問題が原因だと思い、googleってみると、やはりありました。</p>
<blockquote><p>
うーん、ちゃんと接続切れない。原因不明。<br />
そういえばNOD32がのHTTPチェックがきいていた。でもこの前はsendが送れなかっただけのはず（その時はsocket.ioじゃなかったけど）</p>
<p>http://d.hatena.ne.jp/motsat/20110411/1302530960</p>
<p>一応今回もHTTPチェックを解除。<br />
そして、socket.io版のコードを試す。<br />
接続切れなくなった。</p>
<p>不思議なことが起こったら、NOD32を疑うことからはじめよう。忘れていました。<br />
<a href="http://d.hatena.ne.jp/motsat/20110421/1303346364"><br />
socket.ioのwebsocket接続がdisconnected、connectedを繰り返してしまう</a>
</p></blockquote>
<blockquote><p>
Firewall (kaspersky/avast) blocked messages when I using websocket server (socket.io on node.js), what can i do? (except change default setting in firewall) port 8080 or 8000 thx a lot</p>
<p><a href="http://stackoverflow.com/questions/5305770/firewall-blocks-websocket">Firewall blocks websocket @ Stackoverflow</a>
</p></blockquote>
<p>
　どうやらNOD32, Avast!, Kasperskyあたりのウイルス対策ソフトはwebsocketでの通信を不正なアクセスか何かと誤認することがあるみたいです。<br />
ウェブ関連の機能を停止したところ、ChromeもFirefox6も問題なく通信することができました。
</p>
<p>
　たぶんFirefoxのxhr-pollingしか動作を確認してなかったから気づかなかっただけで、おそらく、0.7xでもchromeなどでは動いてなかったんだと思います。</p>
]]></content:encoded>
			<wfw:commentRss>http://arakata-kimagure.net/2011/09/06/websocket-socket-io%e3%81%a7%e3%81%ae%e9%80%9a%e4%bf%a1%e3%81%8c%e3%80%81%e3%82%a2%e3%83%b3%e3%83%81%e3%82%a6%e3%82%a4%e3%83%ab%e3%82%b9%e3%82%bd%e3%83%95%e3%83%88%e3%81%ab%e9%81%ae%e6%96%ad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Amazon EC2 Node.js, npm, Socket.IOをインストール</title>
		<link>http://arakata-kimagure.net/2011/09/02/amazon-ec2-node-js-npm-socket-io%e3%82%92%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=amazon-ec2-node-js-npm-socket-io%25e3%2582%2592%25e3%2582%25a4%25e3%2583%25b3%25e3%2582%25b9%25e3%2583%2588%25e3%2583%25bc%25e3%2583%25ab</link>
		<comments>http://arakata-kimagure.net/2011/09/02/amazon-ec2-node-js-npm-socket-io%e3%82%92%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 08:16:50 +0000</pubDate>
		<dc:creator>sjun</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[AmazonEC2]]></category>
		<category><![CDATA[Node.js]]></category>
		<category><![CDATA[npm]]></category>
		<category><![CDATA[Socket.IO]]></category>

		<guid isPermaLink="false">http://arakata-kimagure.net/?p=168</guid>
		<description><![CDATA[Amazon EC2にNode.js, npm, Socket.IOをインストール。 Node.js単体に関してはこちらの記事とほぼ同様の流れ。 Amazon Web Serviceでnode.jsを起動させてみた ここ [...]]]></description>
			<content:encoded><![CDATA[<p>Amazon EC2にNode.js, npm, Socket.IOをインストール。</p>
<p>Node.js単体に関してはこちらの記事とほぼ同様の流れ。<br />
<a href="http://blogs.itmedia.co.jp/kichi/2010/11/amazon-web-serv.html">Amazon Web Serviceでnode.jsを起動させてみた</a></p>
<pre class="brush: bash; title: ; notranslate">
wget http://nodejs.org/dist/node-v0.4.11.tar.gz
tar xvzf node-v0.4.11.tar.gz
cd node-v0.4.11
</pre>
<pre class="brush: bash; title: ; notranslate">
ec2-user&gt; ./configure
Checking for program g++ or c++          : not found
Checking for program icpc                : not found
Checking for program c++                 : not found
/home/ec2-user/node-v0.4.11/wscript:232: error: could not configure a cxx compiler!
~/node-v0.4.11
</pre>
<p>
ここで、コンパイラがないとおこられる
</p>
<pre class="brush: bash; title: ; notranslate">
sudo yum install gcc-c++
sudo yum install openssl-devel
</pre>
<p>もし無い場合はopenssl-develも、私の場合はもうつかってたのでなし。</p>
<p>
これでいけるか、と思ったが、突然重くなって落ちた。Googleさんに尋ねてみたところ、この2つの記事に出くわす。<br />
<a href="http://fungoing.blogspot.com/2010/12/nodejsamazon-ec2micro.html">node.jsをAmazon EC2のmicroインスタンスに入れる時の注意 </a><br />
<a href="http://d.hatena.ne.jp/t_43z/20110304/1299222231">Amazon EC2 MicroインスタンスのAmazon LinuxにNodeをインストールした</a><br />
どうやら、CPU負荷が高くなりすぎて、make中にkillされてしまったらしい。
</p>
<p>ただ、make cleanして、もういちど./configure, make, make installしたところすぐ終了。</p>
<pre class="brush: bash; title: ; notranslate">
ec2-user&gt; ./configure
Checking for program g++ or c++          : /usr/bin/g++
Checking for program cpp                 : /usr/bin/cpp
Checking for program ar                  : /usr/bin/ar
Checking for program ranlib              : /usr/bin/ranlib
Checking for g++                         : ok
Checking for program gcc or cc           : /usr/bin/gcc
Checking for gcc                         : ok
Checking for library dl                  : yes
Checking for openssl                     : yes
Checking for library util                : yes
Checking for library rt                  : yes
--- libeio ---
Checking for library pthread             : yes
Checking for function pthread_create     : yes
Checking for function pthread_atfork     : yes
Checking for futimes(2)                  : yes
Checking for readahead(2)                : yes
Checking for fdatasync(2)                : yes
Checking for pread(2) and pwrite(2)      : yes
Checking for sendfile(2)                 : yes
Checking for sync_file_range(2)          : yes
--- libev ---
Checking for header sys/inotify.h        : yes
Checking for function inotify_init       : yes
Checking for header sys/epoll.h          : yes
Checking for function epoll_ctl          : yes
Checking for header port.h               : not found
Checking for header poll.h               : yes
Checking for function poll               : yes
Checking for header ['sys/types.h', 'sys/event.h'] : not found
Checking for header sys/queue.h                    : yes
Checking for function kqueue                       : not found
Checking for header sys/select.h                   : yes
Checking for function select                       : yes
Checking for header sys/eventfd.h                  : yes
Checking for function eventfd                      : yes
Checking for SYS_clock_gettime                     : yes
Checking for library rt                            : yes
Checking for function clock_gettime                : yes
Checking for function nanosleep                    : yes
Checking for function ceil                         : yes
Checking for fdatasync(2) with c++                 : yes
'configure' finished successfully (3.415s)
~/node-v0.4.11
</pre>
<pre class="brush: bash; title: ; notranslate">
ec2-user&gt; node -v
v0.4.11
</pre>
<p>ちゃんと、/usr/local/bin/nodeに入ってる。</p>
<p>
次にnpm のインストール<br />
EC2ではないけれど、この記事が非常に参考になった。<br />
<a href="http://www.giantflyingsaucer.com/blog/?p=1688">Installing Node.js and NPM on Ubuntu 10.04 and try a simple chat application</a><br />
一時的に/usr/localの所有権を$USERに移してるのは、インストールコマンドを実行するため。<br />
sudo shだとよくないってどっかに書いてあった気がするけど忘れた。汗
</p>
<pre class="brush: bash; title: ; notranslate">
sudo chown -R $USER /usr/local
curl http://npmjs.org/install.sh | sh
sudo chown -R root /usr/local
npm -v
1.0.27
</pre>
<p>npmインストールされた！<br /> 次に、socket.io</p>
<pre class="brush: bash; title: ; notranslate">
sudo npm install socket.io
sudo: npm: command not found
~
</pre>
<p>
???<br />
というわけで、困ったときのStackoverflowさんに聞いてみる。
</p>
<p><a href="http://stackoverflow.com/questions/257616/sudo-changes-path-why">sudo changes PATH &#8211; why?</a><br />
<a href="http://stackoverflow.com/questions/4976658/on-ec2-sudo-node-command-not-found-but-node-without-sudo-is-ok">On EC2: sudo node command not found, but node without sudo is ok</a></p>
<p>
どうやら、sudo したときのPATHの設定がセキュリティの関係上リセットされるらしい。<br />
しかも、/usr/local/binをPATHに読み込んでくれない。なので、visudoでpathに/usr/local/binを追加する。
</p>
<pre class="brush: bash; title: ; notranslate">
sudo visudo

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
</pre>
<pre class="brush: bash; title: ; notranslate">
ec2-user&gt; sudo npm install socket.io
socket.io@0.8.2 ./node_modules/socket.io
├── policyfile@0.0.4
├── redis@0.6.6
└── socket.io-client@0.8.2
~
</pre>
<p>/usr/local/binにPATHが通って、sudoからnpm, nodeできるように！</p>
]]></content:encoded>
			<wfw:commentRss>http://arakata-kimagure.net/2011/09/02/amazon-ec2-node-js-npm-socket-io%e3%82%92%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP if文: if{}とif: endif;</title>
		<link>http://arakata-kimagure.net/2011/08/20/php-if%e6%96%87-if%e3%81%a8if-endif/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-if%25e6%2596%2587-if%25e3%2581%25a8if-endif</link>
		<comments>http://arakata-kimagure.net/2011/08/20/php-if%e6%96%87-if%e3%81%a8if-endif/#comments</comments>
		<pubDate>Sat, 20 Aug 2011 04:57:40 +0000</pubDate>
		<dc:creator>sjun</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://arakata-kimagure.net/?p=159</guid>
		<description><![CDATA[phper(phpist?)では無いんですが、最近php書くことが多いので、まあ、逆に言えば、phperでないがゆえのメモ。 まずはよくあるパターンから 一行程度を表示させたい時の条件分岐 表示させたい時が沢山あるときの [...]]]></description>
			<content:encoded><![CDATA[<p>
phper(phpist?)では無いんですが、最近php書くことが多いので、まあ、逆に言えば、phperでないがゆえのメモ。<br />
まずはよくあるパターンから
</p>
<p>
一行程度を表示させたい時の条件分岐</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php if($hoge){
     echo $hage;
  }else{
     echo $huge;
  }
?&gt;
</pre>
</p>
<p>
表示させたい時が沢山あるときの条件分岐</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php if($this-&gt;value): ?&gt;
  Hello
&lt;?php elseif($this-&gt;asd): ?&gt;
  Your name is: &lt;?= $this-&gt;name ?&gt;
&lt;?php else: ?&gt;
  You don't have a name.
&lt;?php endif; ?&gt;
</pre>
</p>
<p>
要は、if{}もif: endif;も同じだけど、<br />
echoをたくさん書くのは、MVC使ってるときにやるのいやでしょ？ってことらしいです。</p>
<blockquote><p>
They are the same but the second one is great if you have MVC in your code and don&#8217;t want to have a lot of echos in your code. F.e. in my .phtml files (Zend Framework) I will write something like this:</p></blockquote>
<p>
別にif(): endif;じゃなくても、以下のようにすれば、複数行でいけるみたいですが…。<br />
全然美しくない&#8230;
</p>
<pre class="brush: php; title: ; notranslate">
&lt;? if($condition) { ?&gt;
   HTML content here
&lt;? } else { ?&gt;
   Other HTML content here
&lt;? } ?&gt;
</pre>
<p>works cited<br />
<a href="http://stackoverflow.com/questions/564130/difference-between-if-and-if-endif">http://stackoverflow.com/questions/564130/difference-between-if-and-if-endif</a></p>
]]></content:encoded>
			<wfw:commentRss>http://arakata-kimagure.net/2011/08/20/php-if%e6%96%87-if%e3%81%a8if-endif/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Closure (2): 何ができるのか</title>
		<link>http://arakata-kimagure.net/2011/06/30/closure-2-%e4%bd%95%e3%81%8c%e3%81%a7%e3%81%8d%e3%82%8b%e3%81%ae%e3%81%8b/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=closure-2-%25e4%25bd%2595%25e3%2581%258c%25e3%2581%25a7%25e3%2581%258d%25e3%2582%258b%25e3%2581%25ae%25e3%2581%258b</link>
		<comments>http://arakata-kimagure.net/2011/06/30/closure-2-%e4%bd%95%e3%81%8c%e3%81%a7%e3%81%8d%e3%82%8b%e3%81%ae%e3%81%8b/#comments</comments>
		<pubDate>Thu, 30 Jun 2011 11:57:24 +0000</pubDate>
		<dc:creator>sjun</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[closure]]></category>

		<guid isPermaLink="false">http://arakata-kimagure.net/?p=150</guid>
		<description><![CDATA[前回の記事で、「クロージャは、スコープの外側から内部にアクセスできるということ」であること、つまりWhatの部分を学習した。しかし、それだけではクロージャが何に使えるのか、どうして使うのかといった、How, Whyの部分 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://arakata-kimagure.net/?p=107">前回の記事</a>で、「クロージャは、スコープの外側から内部にアクセスできるということ」であること、つまりWhatの部分を学習した。しかし、それだけではクロージャが何に使えるのか、どうして使うのかといった、How, Whyの部分がわからない。よって、今回は、それが<strong>いったい何に使えるのか</strong>、つまり、<strong>Howの部分</strong>を理解したい。</p>
<p>まず、先に<strong>結論</strong>から言ってしまうと、<strong>プライベートメンバを実装できる</strong>。</p>
<p>まず、プライベートメソッドについて、<a href="https://developer.mozilla.org/en/JavaScript/Guide/Closures">MDNのClosureの頁</a>が、簡潔にまとめてくれているのでそれを引用したい。
<p> &#8220;Javaのような言語は、プライベートメソッド、つまり同じクラスからのみ呼び出せるメソッドを宣言できる。</p>
<p>     JavaScriptは、ネイティブにプライベートメソッドを生成することはできないが、クロージャを使ってそれを真似することができる。プライベートメソッドは、単に<strong>コードへのアクセスを制限</strong>するだけでなく、それを使うことによって、<strong>グローバルな名前空間を強力に管理</strong>し、コード中に<strong>不要なメソッドをまき散らすことも避けられる</strong>。&#8221;</p>
<blockquote><p>Languages such as Java provide the ability to declare methods private, meaning that they can only be called by other methods in the same class.<br />
JavaScript does not provide a native way of doing this, but it is possible to emulate private methods using closures. Private methods aren&#8217;t just useful for restricting access to code: they also provide a powerful way of managing your global namespace, keeping non-essential methods from cluttering up the public interface to your code.</p>
</blockquote>
<p>また、プライベートメソッドと同様に、プライベートな変数を宣言することもできる。<br />
プライベートメンバについては、少し長いが、Pro Javascript Design Patterns P.33 のPrivate Members Through Closuresにある例が非常にわかりやすいので、これを一部引用したい。</p>
<pre class="brush: jscript; title: ; notranslate">
var Book = function(newIsbn, newTitle, newAuthor) { // implements Publication

     // プライベートメンバ
     var isbn, title, author;
     // プライベートメソッド
     function checkIsbn(isbn) {
          ...
     }

     // 以下、特権付きメソッド
     this.getIsbn = function() {
          return isbn;
     };
     this.setIsbn = function(newIsbn) {
          if(!checkIsbn(newIsbn)) throw new Error('Book: Invalid ISBN.');
          isbn = newIsbn;
     };
     this.getTitle = function() {
          return title;
     };
     this.getAuthor = function() {
          return author;
     };
}
</pre>
<p>この例では、Book関数の中にある、isbn, title, authorといったプライベートな変数、checkIsbnというプライベートメソッドには、クロージャによって囲われているため、この関数の外側からは直接に全くアクセスできない。しかし、それらにアクセスする方法はある。</p>
<p>”プライベートメソッド、変数にアクセスするメソッドは、全てBook内で宣言されている必要がある。これらは、パブリックであるがプライベートなメソッドと変数にアクセスできるため、特権付きメソッド(privileged method)と呼ばれている。”</p>
<blockquote><p>Any method that needs to access these variables and functions need only be declared<br />
within Book. These are called privileged methods because they are public but have access to<br />
private attributes and methods.</p></blockquote>
<p>つまり、<strong>プライベートメンバを宣言している関数の内部に、それにアクセスするためのメソッドをつくり、そのメソッドに外部からアクセスすることによって、プライベートメンバにアクセスできるようにしている</strong>のだ。</p>
<p>以上クロージャによって、<strong>プライベートメンバ</strong>(= プライベートメソッド、変数)を作成することができ、それによって、<strong>(1)コードのアクセスの制限、(2)名前空間の管理、(3)コード中にメソッドを書き散らすことを防ぐ</strong>ことができる。</p>
]]></content:encoded>
			<wfw:commentRss>http://arakata-kimagure.net/2011/06/30/closure-2-%e4%bd%95%e3%81%8c%e3%81%a7%e3%81%8d%e3%82%8b%e3%81%ae%e3%81%8b/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iCloud、それは、Googleにとっては迷惑、Microsoftにとっては屈辱。</title>
		<link>http://arakata-kimagure.net/2011/06/13/icloud%e3%80%81%e3%81%9d%e3%82%8c%e3%81%af%e3%80%81google%e3%81%ab%e3%81%a8%e3%81%a3%e3%81%a6%e3%81%af%e8%bf%b7%e6%83%91%e3%80%81microsoft%e3%81%ab%e3%81%a8%e3%81%a3%e3%81%a6%e3%81%af%e5%b1%88/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=icloud%25e3%2580%2581%25e3%2581%259d%25e3%2582%258c%25e3%2581%25af%25e3%2580%2581google%25e3%2581%25ab%25e3%2581%25a8%25e3%2581%25a3%25e3%2581%25a6%25e3%2581%25af%25e8%25bf%25b7%25e6%2583%2591%25e3%2580%2581microsoft%25e3%2581%25ab%25e3%2581%25a8%25e3%2581%25a3%25e3%2581%25a6%25e3%2581%25af%25e5%25b1%2588</link>
		<comments>http://arakata-kimagure.net/2011/06/13/icloud%e3%80%81%e3%81%9d%e3%82%8c%e3%81%af%e3%80%81google%e3%81%ab%e3%81%a8%e3%81%a3%e3%81%a6%e3%81%af%e8%bf%b7%e6%83%91%e3%80%81microsoft%e3%81%ab%e3%81%a8%e3%81%a3%e3%81%a6%e3%81%af%e5%b1%88/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 11:42:09 +0000</pubDate>
		<dc:creator>sjun</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[iOS]]></category>

		<guid isPermaLink="false">http://arakata-kimagure.net/?p=135</guid>
		<description><![CDATA[For Google, iCloud Is Annoying; For Microsoft, It&#8217;s A Humiliation Pascal-Emmanuel Gobry, Friday, June 10 [...]]]></description>
			<content:encoded><![CDATA[<h4><a href="http://www.sfgate.com/cgi-bin/article.cgi?f=/g/a/2011/06/10/businessinsider-apple-icloud-microsoft-cloud-2011-6.DTL">For Google, iCloud Is Annoying; For Microsoft, It&#8217;s A Humiliation</a></h4>
<p>Pascal-Emmanuel Gobry, Friday, June 10, 2011</p>
<p><img alt="" src="http://static8.businessinsider.com/image/4dee390e4bd7c8f842280000/steve-jobs-icloud.jpg" title="jobs"  width="400" height="300" /></p>
<p>Appleがクラウドコンピューティングに加わることが明らかになった今、最も有名なコンシューマクラウドコンピューティングの会社であるGoogleと、Appleのやり方がどれだけ違うのかをみてみることは、面白いことに違いない。実は、アップルのクラウドに対するビジョンは、Googleのそれとは大きく違っている。</p>
<blockquote><p>When it became obvious Apple would come out with a cloud computing offering, it would be interesting to see how they would do things differently from Google, the most prominent consumer cloud computing company. And indeed, Apple&#8217;s vision for the cloud is very different from Google&#8217;s. </p></blockquote>
<p>なんと、Appleのビジョンは、Microsoftのクラウドに対するビジョンと、非常によく似ているのだ。</p>
<blockquote><p>In fact, Apple&#8217;s vision for the cloud is pretty much Microsoft&#8217;s vision for the cloud. </p></blockquote>
<p>そして、Microsoftが遠い昔にやるはずだったことを、Appleがやったというのは、Microsoftにとって非常に耐え難いことだ。</p>
<blockquote><p>And it&#8217;s pretty humiliating for the Redmond company that Apple did what Microsoft should have done a long time ago. </p></blockquote>
<p>Googleにとっては、クラウドは 「クラウド + WEB」で、Appleにとっては、クラウド + インターネットのあちら側で物事を処理するソフトウェア:これが、GoogleとAppleのビジョンの違いだ。</p>
<blockquote><p>Here&#8217;s how Google and Apple&#8217;s vision of the cloud differ: for Google, the cloud means cloud + web; for Apple, cloud computing means cloud + software, with the internet stuff happening behind the scenes. </p></blockquote>
<p>Googleが消費者に提供するクラウドコンピューティングサービス、例えば、Eメール、ワードプロセッサ、スプレッドシートなどといったものは、全て、ブラウザの中で起きることだ。Googleにとって、クラウドコンピューティングの要は、Webによって、デスクトップのソフトを置き換えてしまうということなのだ。</p>
<blockquote><p>All of the cloud computing services Google offers to consumers, like email, word processing and spreadsheets, happen within the browser. To Google, the point of cloud computing is to replace desktop software with the web.
</p></blockquote>
<p>Appleにとって、クラウドコンピューティングというのは、ソフトウェアの代替ではなく、デスクトップのソフトウェアを補強するものなのだ。Eメールやデータ、曲など、全てものは、バックアップを不要ものとし、どこからでもアクセスできるようにするため、まるで魔法のように自動でクラウドに同期される。Appleにとって、クラウドコンピューティングの要点は、ソフトウェアをより良いものすることにあるのだ。</p>
<blockquote><p>For Apple, cloud computing doesn&#8217;t replace software, it augments it. All of your email, data, songs and stuff is automagically synced to the cloud so that you don&#8217;t have to do backups and you can access it anywhere. To Apple, the point of cloud computing is to make the software better.
</p></blockquote>
<p>実は、それは、クラウドコンピューティングについてMicrosoftが延々とに言ってきた(しかし、実際には行っていない)ことでもある。</p>
<blockquote><p>That also happens to be what Microsoft has been saying (but not really doing) about cloud computing forever.</p></blockquote>
<p>彼らのクラウドコンピューティングに対するスローガンは、いつも、ソフトウェア+サービス(Software plus Service)だった。つまり、全てをブラウザ上で置き換えるには、デスクトップ上のクライアントソフトは、高機能すぎるということだ。(そして、Microsoftは今のところ正しい。Google SpreadsheetはExcelの相手になってすらいない。) だがしかし、クラウドサービスは、ソフトウェアを補強することができるのだ。</p>
<blockquote><p>Microsoft&#8217;s slogan for cloud computing has always beeen &#8220;Software plus Services.&#8221; In other words, client software on the desktop is too rich and interactive to be replaced with everything in the browser (and they&#8217;re right, so far&#8211;Google Spreadsheet is just no match for Excel), but cloud services can augment the software.
</p></blockquote>
<p>Appleが見せたように、これは、Googleに代わるパワフルなビジョンである。デスクトップの高機能性と使いやすさ、そして、クラウドコンピューティングの(オートセーブ、同期、バックアップが不要であること、どこからでもアクセスできるといった)優れた点をそれぞれ良いとこ取りした環境をつくりだすことができるのだ。</p>
<blockquote><p>This is an alternative vision to Google&#8217;s and also a powerful one, as Apple has shown. You can create an environment that&#8217;s &#8220;the best of both worlds&#8221;: the richness and user friendliness of desktop software, and the advantages of cloud computing (autosave, syncing, no backups, access anywhere).
</p></blockquote>
<p>Microsoftにとっての問題は、ビジョンを実現するため、10年余りの歳月があったのにもかかわらず、iCloudのようなものを思いつけなかったことだ。一方、Appleも試はしていたが、柄にもなく、優れたクラウドサービスを提供することに何度も失敗を繰り返した。(つまり、MobileMe and .Mac のようなガラクタ)</p>
<blockquote><p>The problem for Microsoft is that they had almost a decade to come up with something like iCloud to realize that vision, and they didn&#8217;t. Meanwhile Apple tried and, uncharacteristically, failed and failed over again to build a strong cloud offering (MobileMe and .Mac before it were duds).
</p></blockquote>
<p>Googleにとって、iCloudというのは悩ましい。なぜなら、iCloudは、消費者にとって、Androidと比べた時、iOSをより魅力的なものにするからだ。</p>
<blockquote><p>For Google, iCloud is an annoyance, because it makes iOS even more appealing to consumers vis-à-vis Android. </p></blockquote>
<p>Microsoftにとって 、iCloudというのは屈辱である。</p>
<blockquote><p>For Microsoft, iCloud is a humiliation. </p></blockquote>
<p>&#8212;-</p>
<p>
Googleのビジョンを実現するためには、Webブラウザが、今より遙かに高機能に進化しなくては不可能だろう。そしてブラウザの進化には、長い時間がかかることは、今までのHTMLをめぐる歴史を見れば明らかだ。はたして、どちらがユーザーの心をつかみとるのだろうか･･･。</p>
]]></content:encoded>
			<wfw:commentRss>http://arakata-kimagure.net/2011/06/13/icloud%e3%80%81%e3%81%9d%e3%82%8c%e3%81%af%e3%80%81google%e3%81%ab%e3%81%a8%e3%81%a3%e3%81%a6%e3%81%af%e8%bf%b7%e6%83%91%e3%80%81microsoft%e3%81%ab%e3%81%a8%e3%81%a3%e3%81%a6%e3%81%af%e5%b1%88/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Closure (1): クロージャとは何か</title>
		<link>http://arakata-kimagure.net/2011/06/08/closure-1-%e3%82%af%e3%83%ad%e3%83%bc%e3%82%b8%e3%83%a3%e3%81%a8%e3%81%af%e4%bd%95%e3%81%8b/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=closure-1-%25e3%2582%25af%25e3%2583%25ad%25e3%2583%25bc%25e3%2582%25b8%25e3%2583%25a3%25e3%2581%25a8%25e3%2581%25af%25e4%25bd%2595%25e3%2581%258b</link>
		<comments>http://arakata-kimagure.net/2011/06/08/closure-1-%e3%82%af%e3%83%ad%e3%83%bc%e3%82%b8%e3%83%a3%e3%81%a8%e3%81%af%e4%bd%95%e3%81%8b/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 07:43:33 +0000</pubDate>
		<dc:creator>sjun</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[closure]]></category>

		<guid isPermaLink="false">http://arakata-kimagure.net/?p=107</guid>
		<description><![CDATA[どうにもJavaScriptのクロージャがややこしくて困る。どうも原因は、関数スコープしかスコープが無いことが原因のようなのだが、文句だけ言っても先に進まないので、手を尽くして調べてみた。 2000ページを超える Jav [...]]]></description>
			<content:encoded><![CDATA[<p>どうにもJavaScriptのクロージャがややこしくて困る。どうも原因は、関数スコープしかスコープが無いことが原因のようなのだが、文句だけ言っても先に進まないので、手を尽くして調べてみた。</p>
<p>2000ページを超える JavaScript Bibleによると、定義は以下のようになる。</p>
<p>「JavaScriptのコアの部分では、closureというのは、ある関数の中で定義されたローカル変数を、その関数が実行された後でさえ、生かすことができるという事実を意味する。- 普通は、ローカル変数は関数が実行された後に終わりをむかえるのだ。」</p>
<blockquote><p>     At the core of JavaScript, closures refer to the fact that you can keep a local variable defined in a function alive even after the function has executed — which normally signals the end of life for a local variable — Javascript Bible P.456</p></blockquote>
<p>つまり、普通は、関数でスコープを作ると、その関数の外からアクセスできないようになるのだけれど、クロージャがあると、その関数スコープの外から、その関数内の変数にアクセスできるようになるということ、らしい。とは言っても、言葉だけではよくわからないので、実際にみてみよう。</p>
<p>e.g.</p>
<pre class="brush: jscript; title: ; notranslate">
function f(){
     var b = &quot;b&quot;;
     return function(){
          return b;
     }
}
</pre>
<p>
ここで、<br />
<strong>b</strong> => undefined<br />
としても、当然ではあるのだけれど、グローバルのスコープからは、関数のスコープを覗くことはできないので、b は、undefinedを返す。</p>
<p>そこで、以下のように、f()から、関数g()を生成すると、
</p>
<pre class="brush: jscript; title: ; notranslate">
var g = f();
g();
</pre>
<p>
<strong>g();</strong>  => b</p>
<p>f()のスコープの外側から、f()内の変数にアクセスできる。
</p>
<p>ここでは、「クロージャがどういうものか」を見たが、それがいったい何の役に立つのか、それから、これはクラスと何が違うのか(厳密な意味では、JavaScriptにクラスは無いが)、クロージャのパフォーマンスあたりについては、よくわからないので、次回以降順番に見ていきたい。</p>
<p>  <a href="http://arakata-kimagure.net/?p=150">Closure (2) 何が出来るのか</a></p>
]]></content:encoded>
			<wfw:commentRss>http://arakata-kimagure.net/2011/06/08/closure-1-%e3%82%af%e3%83%ad%e3%83%bc%e3%82%b8%e3%83%a3%e3%81%a8%e3%81%af%e4%bd%95%e3%81%8b/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery 1.6.1 のリリースに関して (日本語訳)</title>
		<link>http://arakata-kimagure.net/2011/05/24/jquery-1-6-1-%e3%81%ae%e3%83%aa%e3%83%aa%e3%83%bc%e3%82%b9/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-1-6-1-%25e3%2581%25ae%25e3%2583%25aa%25e3%2583%25aa%25e3%2583%25bc%25e3%2582%25b9</link>
		<comments>http://arakata-kimagure.net/2011/05/24/jquery-1-6-1-%e3%81%ae%e3%83%aa%e3%83%aa%e3%83%bc%e3%82%b9/#comments</comments>
		<pubDate>Tue, 24 May 2011 13:47:43 +0000</pubDate>
		<dc:creator>sjun</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://arakata-kimagure.net/?p=77</guid>
		<description><![CDATA[Originally posted May 12th, 2011 by John Resig http://blog.jquery.com/2011/05/12/jquery-1-6-1-released/ 1.5.2か [...]]]></description>
			<content:encoded><![CDATA[<p>Originally posted May 12th, 2011 by John Resig<br />
<a href="http://blog.jquery.com/2011/05/12/jquery-1-6-1-released/" target="_blank">http://blog.jquery.com/2011/05/12/jquery-1-6-1-released/</a></p>
<div>
<h3>1.5.2から、1.6.1へのアップグレード</h3>
<p>新しい.prop()メソッドの導入と、.attr()メソッドへの変更によって、jQuery1.6は、属性とプロパティの違いや関連性について喧々囂々の議論を繰り広げることになり、1.6.1で既に修正にされた後方互換性の問題も、それに加わったが、<strong>1.5.2から1.6.1へのアップグレードにあたっては、何も属性コードに変更を加える必要はない。</strong></p>
<blockquote>
<div>With the introduction of the new .prop() method and the changes to the .attr() method, jQuery 1.6 sparked a discussion about the difference between  attributes and properties and how they relate to each other. It also  came with some backwards compatibility issues that have been fixed in  1.6.1. <strong>When updating from 1.5.2 to 1.6.1, you should not have to change any attribute code.</strong></div>
</blockquote>
<p>以下は、.attr()メソッドと.prop()メソッド<strong>好ましい</strong>使い方とjQuery 1.6と1.6.1のAttributeモジュールの変更点についての説明である。しかしながら、前述のとおり、jQuery 1.6,1は、あらゆる状況で、前に使われていたのと全く同じように.attr()属性を使うことを可能にしている。</p>
<blockquote>
<div>Below is a description of the changes to the Attributes module in jQuery 1.6 and 1.6.1, as well as the <em>preferred</em> usage of the .attr() method and the .prop() method. However, as previously stated, jQuery 1.6.1 will allow you to use .attr() just as it was used before in all situations.</div>
</blockquote>
<p>.data()メソッドに関しては、1.6のリリースノートに書いたような変更は修正され、1.5.2と1.6.1間ではシームレスに動作するようになった。</p>
<blockquote>
<div>Note that the changes described in the 1.6 release notes regarding the .data() method have been worked around and now work seamlessly between 1.5.2 and 1.6.1.</div>
</blockquote>
<h3>何が変わったのか</h3>
<p>Attributeモジュールへの変更によって、属性とプロパティのまぎらわしさは消えたが、1.6以前の全てのバージョンで、属性とプロパ ティをattr()という一つのメソッドで扱っていたため、 jQueryコミュニティに混乱を招いた。古い  .attr()メソッドは沢山のバグがあり、維持することが困難だったのだ。</p>
<blockquote>
<div>The changes to the Attributes module removed the ambiguity between  attributes and properties, but caused some confusion in the jQuery  community, since all versions of jQuery prior to 1.6 have handled  attributes and properties in one method(.attr()). The old .attr() method had many bugs and was hard to maintain.</div>
</blockquote>
<p>jQuery 1.6.1では、Attributeモジュールのアップデートとともに、いくつかのバグ修正が行われた。</p>
<blockquote>
<div>jQuery 1.6.1 comes with several bug fixes as well as an update to the Attributes module.</div>
</blockquote>
<p>特に、1.6.1における、checked, selected, readonly, そして, disabledなどといった真偽(Boolean)属性は、1.6以前と同様に扱われる。これによって、</p>
<pre class="brush: jscript; title: ; notranslate">
$(“:checkbox”).attr(“checked”, true);
$(“option”).attr(“selected”, true);
$(“input”).attr(“readonly”, true);
$(“input”).attr(“disabled”, true);
</pre>
<p>や</p>
<pre class="brush: jscript; title: ; notranslate">if ( $(“:checkbox”).attr(“checked”) ) { /* Do something */ }</pre>
<p>という、コードでさえ、1.6.1では変更は必要ない。</p>
<blockquote><p>Specifically, boolean attributes such as checked, selected,  readonly, and disabled in 1.6.1 will be treated just as they used to be  treated in jQuery versions prior to 1.6. This means that code such as</p>
<pre>
$(“:checkbox”).attr(“checked”, true);
$(“option”).attr(“selected”, true);
$(“input”).attr(“readonly”, true);
$(“input”).attr(“disabled”, true);
</pre>
<p>or even:</p>
<pre>if ( $(“:checkbox”).attr(“checked”) ) { /* Do something */ }</pre>
<p>will not need to be changed in 1.6.1 in order to work as previously expected.</p></blockquote>
<p>1.6.1における.attr()への変更点をはっきりさせると、以下のようになる。これらが、今までのバージョンで.attr()属性として機能していたもので、.prop()で置き換えられるべきケースである。</p>
<blockquote><p>To make the changes to .attr() in jQuery 1.6 clear, here are some examples of the use cases of .attr() that worked in previous versions of jQuery that should be switched to use .prop() instead:</p></blockquote>
<div>
<table>
<tbody>
<tr>
<th>.attr()</th>
<th>適切な .prop() の用法</th>
</tr>
<tr>
<td>$(window).attr…</td>
<td>$(window).prop…</td>
</tr>
<tr>
<td>$(document).attr…</td>
<td>$(document).prop…</td>
</tr>
<tr>
<td>$(“:checkbox”).attr(“checked”, true);</td>
<td>$(“:checkbox”).prop(“checked”, true);</td>
</tr>
<tr>
<td>$(“option”).attr(“selected”, true);</td>
<td>$(“option”).prop(“selected”, true);</td>
</tr>
</tbody>
</table>
</div>
<p>まず、jQuery  1.6では、windowとdocumentは、属性を持つことはできないので、windowとdocument上で.attr()メソッドを動かすこと はできなかった。それらは、.prop()か、単に生のjavascriptで操作されるべき(locationやreadyStateといった)プロパ ティを含んでいる。jQuery  1.6.1では、.attr()は、windowとdocumentの両方でエラーを投げるというという点で、.prop()メソッドとは異なる</p>
<blockquote>
<div>First, using the .attr() method on the window or  document did not work in jQuery 1.6 because the window and document  cannot have attributes. They contain properties (such as location or  readyState) that should be manipulated with .prop() or simply with raw javascript. In jQuery 1.6.1, the .attr() will defer to the .prop() method for both the window and document instead of throwing an error.</div>
</blockquote>
<p>次に、前に言及したchecked, selected、その他の真偽属性は、これらの属性と対応するプロパティとの特別な関係のために特別扱いされる。基本的に、属性は、以下のようにHTMLでみられるようなものである。</p>
<blockquote>
<div>Next, checked, selected, and other boolean attributes previously  mentioned are receiving special treatment because of the special  relationship between these attributes and their corresponding  properties. Basically, an attribute is what you see in the html:</div>
</blockquote>
<pre class="brush: xml; title: ; notranslate">&amp;lt;input type=”checkbox” checked=”checked”&amp;gt;</pre>
<p>checkedのような真偽属性は、デフォルトもしくは<em>初期値</em>のみセットされる。例えば、checkboxの場合、checked属性はページがロードされる時のチェックボックスのチェック状態をセットする。</p>
<blockquote>
<div>Boolean attributes such as checked only set the default or <em>initial</em> value. In the case of a checkbox, the checked attribute sets whether the checkbox should be checked when the page loads.</div>
</blockquote>
<p>プロパティは、ブラウザが監視している現在の値である。普通、プロパティは、(もし存在するならば)それに対応する値が反映される。これは真偽 属性の場合とは違う。真偽プロパティは、ユーザーがセレクト要素でチェックボックスや選択肢をクリックしたときに最新の状態になる。真偽属性の場合はそう はならない。上で述べたように、ブラウザによってセットされた初期値が使われるからだ。</p>
<blockquote>
<div>Properties are what the browser uses to keep track of the <strong>current</strong> values. Normally, properties reflect their corresponding attributes (if  they exist). This is not the case with boolean attributes. Boolean  properties stay up to date when the user clicks a checkbox or selects an  option in a select element. The corresponding boolean attributes do  not. As was stated above, they are used by the browser only to store the  initial value.</div>
</blockquote>
<pre class="brush: jscript; title: ; notranslate">$(“:checkbox”).get(0).checked = true;// Is the same as $(&quot;:checkbox:first&quot;).prop(“checked”, true);</pre>
<p>jQuery 1.6では、checkedを以下のように設定することは、</p>
<pre class="brush: jscript; title: ; notranslate">$(“:checkbox”).attr(“checked”, true);</pre>
<div>
<p>実際にチェックボックスをチェックするというわけではない。というのは、これは設定されるプロパティであって、設定したものは全て初期値だからだ。</p>
<blockquote><p>In jQuery 1.6, setting checked with<br />
$(“:checkbox”).attr(“checked”, true);<br />
would not check the checkbox because it was the property that needed to be set and all you were setting was the initial value.</p></blockquote>
<p>しかしながら、jQuery1.6がリリースされると、jQueryチームは、ブラウザが、ページの読み込み時にのみブラウザが考慮するものを 設定することは、特に有用ではないと理解した。したがって、後方互換性と.attr()メソッドの利便性のために、1.6.1においても.attr()メ ソッドで真偽属性を取得、設定をできるようにした。</p>
<blockquote>
<div>However, once jQuery 1.6 was released, the jQuery team understood  that it was not particularly useful to set something that the browser  was only concerned with on page load. Therefore, in the interest of  backwards compatibility and the usefulness of the .attr() method, we will continue to be able to get and set these boolean attributes with the .attr() method in jQuery 1.6.1.</div>
</blockquote>
<p>一番、一般的な真偽属性は、<strong>checked, selected, disabled</strong><strong>, readOnly</strong>だが、jQuery1.6の.attr()で動的に取得設定をサポートする真偽属性/プロパティの完全なリスト作った。</p>
<blockquote>
<div>The most common boolean attributes are <strong>checked, selected, disabled, and readOnly</strong>, but here is a full list of boolean attributes/properties that jQuery 1.6.1 supports dynamically getting and setting with .attr():</div>
</blockquote>
<p><strong>autofocus, autoplay, async, checked, controls, defer, disabled,hidden, loop, multiple, open, readonly, required, scoped, selected</strong></p>
<p>これらの真偽属性や真偽プロパティを設定する時は、.prop()が推奨される点に変わりはないが、.prop()メソッドへとコードの変更をしなくとも、jQuery1.6.1においてはコードを動かし続けることができる。</p>
<blockquote>
<div><strong>It is still recommended that .prop() be used  when setting these boolean attributes/properties, but your code will  continue working in jQuery 1.6.1 even if these use cases are not  switched to use the .prop() method.</strong></div>
</blockquote>
<p>以下は、いくつかの属性とプロパティと、どのメソッドがそれらの取得/設定時に普通使われるかのリストである。これが、<strong>好ましい</strong>使い方ではあるのだが、.attr()メソッドも全ての属性においてきちんと動作する。</p>
<blockquote>
<div><strong>Below is a list of some attributes and properties and which  method should normally be used when getting or setting them. This is  the <em>preferred</em> usage, but the .attr() method will work in all attribute cases.</strong></div>
</blockquote>
<p>いくつかのDOM要素プロパティも、以下のリストにあるが、新しい.prop()メソッドでしか動かないことに注意して欲しい。</p>
<blockquote><p><strong>Note that some DOM Element properties are also listed below – but will only work with the new .prop() method.</strong></p></blockquote>
<p><strong><br />
</strong></p>
<table>
<tbody>
<tr>
<th>Attribute/Property</th>
<th>.attr()</th>
<th>.prop()</th>
</tr>
<tr>
<td>accesskey</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>align</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>async</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<td>autofocus</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<td>checked</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<td>class</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>contenteditable</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>defaultValue</td>
<td></td>
<td>✓</td>
</tr>
<tr>
<td>draggable</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>href</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>id</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>label</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>location *</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<td>multiple</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<td>nodeName</td>
<td></td>
<td>✓</td>
</tr>
<tr>
<td>nodeType</td>
<td></td>
<td>✓</td>
</tr>
<tr>
<td>readOnly</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<td>rel</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>selected</td>
<td>✓</td>
<td>✓</td>
</tr>
<tr>
<td>selectedIndex</td>
<td></td>
<td>✓</td>
</tr>
<tr>
<td>src</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>style</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>tabindex</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>tagName</td>
<td></td>
<td>✓</td>
</tr>
<tr>
<td>title</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>✓</td>
<td></td>
</tr>
<tr>
<td>width **</td>
<td>✓</td>
<td></td>
</tr>
</tbody>
</table>
<p><strong>*</strong> 例えば、<strong>window.location<br />
** If needed over .width()</strong></p>
<p><strong>.attr()<span style="font-family: Arial;">、</span>.prop()はどちらも値を取得/設定するために使われるべきではない。</strong>.val()メソッドを代わりに使うべきである。<strong>(1.6以前のように、.attr(“value”, “somevalue”)でも動くのだが･･･。).</strong></p>
<blockquote>
<div><strong>Neither .attr() nor .prop() should be used for getting/setting</strong> value. Use the .val() method instead (although using .attr(“value”, “somevalue”) will continue to work, as it did before 1.6).</div>
</blockquote>
<h3>好ましい用法のまとめ</h3>
<p>.prop()メソッドは、真偽属性/プロパティと(window.location)のようなhtmlに存在しないプロパティにつかわれるべきである。他の属性(つまり 、html内に見えるもの)は全て、 .attr()メソッドを使って操作できるし、そうすべきである。</p>
<blockquote>
<div>The .prop() method should be used for boolean  attributes/properties and for properties which do not exist in html  (such as window.location). All other attributes (ones you can see in the  html) can and should continue to be manipulated with the .attr() method.</div>
</blockquote>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://arakata-kimagure.net/2011/05/24/jquery-1-6-1-%e3%81%ae%e3%83%aa%e3%83%aa%e3%83%bc%e3%82%b9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery 1.6 Change Log 抄訳</title>
		<link>http://arakata-kimagure.net/2011/05/12/jquery-1-6-change-log-%e6%8a%84%e8%a8%b3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jquery-1-6-change-log-%25e6%258a%2584%25e8%25a8%25b3</link>
		<comments>http://arakata-kimagure.net/2011/05/12/jquery-1-6-change-log-%e6%8a%84%e8%a8%b3/#comments</comments>
		<pubDate>Thu, 12 May 2011 04:29:27 +0000</pubDate>
		<dc:creator>sjun</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://arakata-kimagure.net/?p=55</guid>
		<description><![CDATA[主な変更点 / Breaking Changes 大半のリリースで、我々は既存のコードとの互換性を保とうと努力しているが、jQuery 1.6では、既存のコードに多少の変更を必要とするかもしれない。 In most re [...]]]></description>
			<content:encoded><![CDATA[<h3>主な変更点 / Breaking Changes</h3>
<p>大半のリリースで、我々は既存のコードとの互換性を保とうと努力しているが、jQuery 1.6では、既存のコードに多少の変更を必要とするかもしれない。</p>
<blockquote><p>In most releases we try to main compatibility with existing code. However, there are a few cases where jQuery 1.6 may require changes to existing code</p></blockquote>
<h3>data-属性における大文字小文字のマッピング / Case-mapping of data- attributes</h3>
<p>jQuery 1.5 は、要素にセットされたどんなdata-属性も、JSONセマンティクスを使って、自動的にそのdata属性をJavascriptの値へ変換する機能を.data()メソッドに導入した。jQuery 1.6では、我々は、-(dash)を埋め込むデータ属性のキャメルケース化に関して、この機能をW3C HTML5の仕様書にマッチするようアップデートした。たとえば、つまり、data-max-value=&#8221;15&#8243;という属性は、jQuery 1.5.2では、{ max-value: 15 }というデータオブジェクトを作成したが、jQuery 1.6では、{ maxValue: 15 }になる。</p>
<blockquote><p>jQuery 1.5 introduced a feature in the .data() method to automatically import any data- attributes that were set on the element and convert them to JavaScript values using JSON semantics. In jQuery 1.6 we have updated this feature to match the W3C HTML5 spec with regards to camel-casing data attributes that have embedded dashes. So for example in jQuery 1.5.2, an attribute of data-max-value=&#8221;15&#8243; would create a data object of { max-value: 15 } but as of jQuery 1.6 it sets { maxValue: 15 }.</p></blockquote>
<h3>.prop(), .removeProp(), .attr()</h3>
<p>1.6のリリースでは、我々は、DOM属性とDOMプロパティのハンドリングを別のメソッドへ分割した。新しい.prop() メソッドは、DOM要素のプロパティを取得/セットし、.removeProp()は、プロパティを削除する。過去、jQueryはプロパティと属性の線引きをあいまいにしていた。一般的に、DOM属性は、&lt;input type=&#8221;text&#8221; value=&#8221;abc&#8221;&gt;のvalue属性のような、HTMLなどから取得されたDOM情報の状態を表し、DOMプロパティは、文書の動的な状態を表す。例えば、ユーザーが上のinput要素をクリックして、defと入力したとしたら、.prop(&#8220;value&#8221;)はabcdefだけれども、.attr(&#8220;value&#8221;)はabcのままである。</p>
<blockquote><p>In the 1.6 release we’ve split apart the handling of DOM attributes and DOM properties into separate methods. The new .prop() method sets or gets properties on DOM elements, and .removeProp() removes properties. In the past, jQuery has not drawn a clear line between properties and attributes. Generally, DOM attributes represent the state of DOM information as retrieved from the document, such as the value attribute in the markup &lt;input type=&#8221;text&#8221; value=&#8221;abc&#8221;&gt;. DOM properties represent the dynamic state of the document; for example if the user clicks in the input element above and types def the .prop(&#8220;value&#8221;) is abcdef but the .attr(&#8220;value&#8221;) remains abc.</p></blockquote>
<p>大半の場合、ブラウザは属性値(attribute value)をプロパティの開始値として扱うが、checkedやdisabledといった、真偽(Boolean)属性は普通とは違うセマンティクスを持つ。</p>
<blockquote><p>In most cases, the browser treats the attribute value as the starting value for the property, but Boolean attributes such as checked or disabled have unusual semantics.</p></blockquote>
<p>例えば、&lt;input type=&#8221;checkbox&#8221; checked&gt;というマークアップを考えてみよう。checked属性の存在は、DOM .checkedプロパティが真であることを意味する、属性は値を持たないけれど。上記のコードでは、checked属性の値は、空の文字列(属性を特定できない場合は、undefined)であるが、checkedプロパティは真になる。</p>
<blockquote><p>For example, consider the markup &lt;input type=&#8221;checkbox&#8221; checked&gt;. The presence of the checked attribute means that the DOM .checked property is true, even though the attribute does not have a value. In the code above, the checked attribute value is an empty string (or undefined if no attribute was specified) but the checked property value is true.</p></blockquote>
<p>jQuery 1.6以前では、.attr(&#8220;checked&#8221;)は、真偽プロパティの値(true)を返したが、jQuery 1.6では、実際の属性の値(つまり、空の文字列)が返され、これはユーザーがチェックボックスをクリックして、状態が変化したときでも変化しない。</p>
<blockquote><p>Before jQuery 1.6, .attr(&#8220;checked&#8221;) returned the Boolean property value (true) but as of jQuery 1.6 it returns the actual value of the attribute (an empty string), which doesn’t change when the user clicks the checkbox to change its state.</p></blockquote>
<p>チェックボックスの現在の状態を調べる代わりの手段がいくつかある。最もパフォーマンスが優れた方法は、クリックされた要素をthisが参照する時の、イベントハンドラ内部のthis.checkedのように、DOMプロパティを直接に使うことだ。jQuery 1.6以降を使うコードでは $(this).prop(&#8220;checked&#8221;)という新しいメソッドが比較的速く、this.checkedと同じ値を取得する。それと、$(this).is(&#8220;:checked&#8221;)という表現なら全てのバージョンのjQueryで動作する。</p>
<blockquote><p>There are several alternatives for checking the currently-checked state of a checkbox. The best and most performant is to use the DOM property directly, as in this.checked inside an event handler when this references the element that was clicked. In code that uses jQuery 1.6 or newer, the new method $(this).prop(&#8220;checked&#8221;) retrieves the same value as this.checked and is relatively fast. Finally, the expression $(this).is(&#8220;:checked&#8221;) works for all versions of jQuery.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://arakata-kimagure.net/2011/05/12/jquery-1-6-change-log-%e6%8a%84%e8%a8%b3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

