<?xml version="1.0" encoding="UTF-8" ?>
<feed xml:lang="ja" xmlns="http://www.w3.org/2005/Atom">
	<generator uri="http://nucleuscms.org/" version="Nucleus CMS v3.31SP1-kes">Nucleus CMS v3.31SP1-kes</generator>

	<id>http://fireball.loafer.jp/kes/</id>
	<link rel="self" type="application/atom+xml" href="http://fireball.loafer.jp/kes/atom.xml" />
	<link rel="related" type="text/html" href="http://fireball.loafer.jp/" />
	<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/" />

	<rights>© 2008 Project Loafer/Project Fireball and all blog writers.</rights>

	<title>Entering Passive Mode</title>
	<subtitle>やる気のない受け身なブログ。実験場。</subtitle>

	<updated>2008-11-09T17:40:36+09:00</updated>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="JavaScript" scheme="http://fireball.loafer.jp/kes/ecmascript/" />
		<content type="html">
<![CDATA[
<pre class="prettyprint">
function foo() {
	;
}

var obj = new Object();
obj.foo = foo;

var x = foo();
var y = new foo();
var z = obj.foo();
</pre>
<p>
関数オブジェクトには 3 つの用途があることが分かった。
</p>
<ul>
<li>関数</li>
<li>コンストラクタ</li>
<li>メソッド</li>
</ul>
<p>
他の言語では、これらは独立していることが多いが、<br />
JavaScript では、全て関数オブジェクトを利用する。<br />
これらを区別するのは、その呼び出し方法である。
</p><a href="http://fireball.loafer.jp/kes/ecmascript/js-invocation.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/ecmascript/js-invocation.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/ecmascript/js-invocation.html" />
		<published>2008-11-09T17:40:36+09:00</published>
		<title type="html"><![CDATA[関数オブジェクトの呼び出し]]></title>
		<updated>2008-11-09T17:40:36+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="JavaScript" scheme="http://fireball.loafer.jp/kes/ecmascript/" />
		<content type="html">
<![CDATA[
<pre class="prettyprint">
function getThisValue() {
	return this.value;
}
function setThisValue(value) {
	this.value = value;
}

function Foo() {
	this.value = 0;
	this.getValue = getThisValue;
	this.setValue = setThisValue;
}

var foo = new Foo();
foo.setValue(3 * 5);
alert(foo.getValue()); // 15
</pre>
<p>
JavaScript では、メソッドもまた関数オブジェクトである。
</p>
<p>
JavaScript においては、メソッドはプロパティの一種であり、<br />
オブジェクトのプロパティに関数オブジェクトを代入すると、<br />
それはメソッドとして呼び出せるようになる。
</p>
<a href="http://fireball.loafer.jp/kes/ecmascript/js-function-as-method.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/ecmascript/js-function-as-method.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/ecmascript/js-function-as-method.html" />
		<published>2008-09-07T19:16:56+09:00</published>
		<title type="html"><![CDATA[メソッドとしての関数オブジェクト]]></title>
		<updated>2008-09-07T19:16:56+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="JavaScript" scheme="http://fireball.loafer.jp/kes/ecmascript/" />
		<content type="html">
<![CDATA[
<pre class="prettyprint">
function Foo(x, y) {
	this.value = x * y;
}

var foo = new Foo(3, 5);
alert(foo.value); // 15
alert(typeof foo); // object
</pre>
<p>
new 演算子で関数オブジェクトを呼び出す事で、<br />
他のプログラミング言語同様、<br />
オブジェクトを生成することができる。
</p>
<a href="http://fireball.loafer.jp/kes/ecmascript/js-function-as-constructor.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/ecmascript/js-function-as-constructor.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/ecmascript/js-function-as-constructor.html" />
		<published>2008-08-18T19:27:18+09:00</published>
		<title type="html"><![CDATA[コンストラクタとしての関数オブジェクト]]></title>
		<updated>2008-08-18T19:27:18+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="JavaScript" scheme="http://fireball.loafer.jp/kes/ecmascript/" />
		<content type="html">
<![CDATA[
<pre class="prettyprint">
foo = new Object(); foo.property = 12345;
bar = new Function("x, y", "return x * y;");
baz = new Array(123, "abc", null);
qux = new String("String object");
quux = new Boolean(true);
corge = new Number(12345);
grault = new Date();
garply = new RegExp("\\d+");
waldo = new Error("No way.");
</pre>
<p>
プリミティブ値はリテラル記法で表現したが、<br />
オブジェクトは主に <dfn>new </dfn> 演算子を使って生成する。
</p>
<p>
<dfn>Function</dfn> オブジェクトに関しては、<br />
<dfn>function</dfn> キーワードを使って作成するのが普通だが、<br />
他と同様、<dfn>new</dfn> 演算子で作成することも可能だ。
</p>
<p>
JavaScript でのオブジェクト生成構文は、<br />
Java や C++ に近くなるように設計されている。
</p>
<p>
ただ、JavaScript ではその文の意味合いが大きく異なる。
</p>
<a href="http://fireball.loafer.jp/kes/ecmascript/js-object-instantiation.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/ecmascript/js-object-instantiation.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/ecmascript/js-object-instantiation.html" />
		<published>2008-08-04T20:04:01+09:00</published>
		<title type="html"><![CDATA[オブジェクトの生成]]></title>
		<updated>2008-08-04T20:04:01+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="JavaScript" scheme="http://fireball.loafer.jp/kes/ecmascript/" />
		<content type="html">
<![CDATA[
<pre class="prettyprint">
function invoke(func, x, y) {
    return func(x, y);
}

function foo(x, y) {
    return x * y;
}

foo.value = invoke(foo, 3, 5);

var bar = foo;

alert(bar.value);
alert(foo.toString());
alert(foo === bar);
</pre>
<p>
JavaScript では、関数はオブジェクトの一種である。<br />
関数は、通常のオブジェクトとしての特性に加え、<br />
() 構文で「呼び出し可能」という特徴を持つ、<br />
特別なオブジェクトとして扱われる。
</p>
<a href="http://fireball.loafer.jp/kes/ecmascript/js-function-object.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/ecmascript/js-function-object.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/ecmascript/js-function-object.html" />
		<published>2008-07-28T22:45:31+09:00</published>
		<title type="html"><![CDATA[関数オブジェクト ]]></title>
		<updated>2008-07-28T22:45:31+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="JavaScript" scheme="http://fireball.loafer.jp/kes/ecmascript/" />
		<content type="html">
<![CDATA[
<pre class="prettyprint">
var value = "String Literal";
var length = value.length;
alert(length);

var value2 = "String Literal";
value2.property = 12345;
alert(value2.property);
</pre>
<p>
<dfn>Number</dfn>, <dfn>String</dfn>, <dfn>Boolean</dfn> の 3 つの型には、<br />
プリミティブとオブジェクトの両方の型が存在する。<br />
違いは、プロパティを持てるか持てないかだ。
</p>
<p>
暗黙の型変換が、色々な場所で適応されるため、<br />
各型に対応するプリミティブ値とオブジェクトは、<br />
ほぼ区別することなく透過的に扱うことができる。
</p>
<p>
また、JavaScript のプロパティアクセサ構文は<br />
プリミティブ値に対しても記述することができるため、<br />
構文上、プリミティブ値にプロパティがあるように見える。
</p>
<p>
これらの言語機能は強力なのだが、プリミティブ値とオブジェクトが、<br />
単一の同じ型であるという誤解を生む原因ともなっている。
</p>
<a href="http://fireball.loafer.jp/kes/ecmascript/js-auto-objectize.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/ecmascript/js-auto-objectize.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/ecmascript/js-auto-objectize.html" />
		<published>2008-07-14T21:46:00+09:00</published>
		<title type="html"><![CDATA[プリミティブのオブジェクト化 ]]></title>
		<updated>2008-07-14T21:46:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="JavaScript" scheme="http://fireball.loafer.jp/kes/ecmascript/" />
		<content type="html">
<![CDATA[
<pre class="prettyprint">
if (new Boolean(false) && "false") {
	alert("Oops!");
}
</pre>
<p>
変数や関数の引数に型を制限できる、型に厳密なプログラミング言語では、<br />
ソースコードを解析した時点で、互換性がない型の値を検出できる。
</p>
<p>
しかし、JavaScript の値の型は常に実行時に決まる。<br />
なので、原則として、その文を実行するまで、<br />
どのような型が渡されるかは検出できない。
</p>
<p>
これが何を意味するかというと、関数の引数等、外部から受け取る値については、<br />
設計者が想定している型である保障がないため、<br />
値を使う前に、型を確認する必要があるということだ。
</p>
<p>
だが、常に型を確認するということは、コーディングの苦痛以外の何者でもないため、<br />
JavaScript は型を制限できない代わりに、自動的・暗黙の型変換を行う仕組みを持っている。
</p><a href="http://fireball.loafer.jp/kes/ecmascript/js-implicit-type-conversion.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/ecmascript/js-implicit-type-conversion.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/ecmascript/js-implicit-type-conversion.html" />
		<published>2008-07-10T23:00:16+09:00</published>
		<title type="html"><![CDATA[暗黙の型変換]]></title>
		<updated>2008-07-10T23:00:16+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="JavaScript" scheme="http://fireball.loafer.jp/kes/ecmascript/" />
		<content type="html">
<![CDATA[
<p>
残りの 2 つのプリミティブ値は、<dfn>undefined</dfn> と <dfn>null</dfn> だ。<br />
これらはよく混同されるので注意が必要である。
<p>
</p>
<dfn>undefined</dfn> は変数（プロパティ）の既定値であり、<br />
存在しないプロパティを参照した際に返される値でもある。
<p>
</p>
<dfn>null</dfn> は、用途は Java や C# と同じで、<br />
空のオブジェクト参照を表すために使われる。
<p>
</p>
まあ、これくらいは基本だろうから、<br />
これらの値をさらに詳しく考えてみよう。
<p>
</p>
JavaScript では、変数や戻り値は型を持たず、<br />
常に値そのものが型（実行時型）を持っている。<br />
<dfn>undefined</dfn> と <dfn>null</dfn> も例外ではなく、それぞれ型が存在する。
<p>
</p>
それは、<dfn>Null</dfn> 型と <dfn>Undefined</dfn> 型だ。<br />
これが、残りの 2 つのプリミティブ型である。
<p><a href="http://fireball.loafer.jp/kes/ecmascript/js-undefined-and-null.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/ecmascript/js-undefined-and-null.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/ecmascript/js-undefined-and-null.html" />
		<published>2008-07-04T20:46:20+09:00</published>
		<title type="html"><![CDATA[Undefined と Null ]]></title>
		<updated>2008-07-04T20:46:20+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="JavaScript" scheme="http://fireball.loafer.jp/kes/ecmascript/" />
		<content type="html">
<![CDATA[
<p>
JavaScript のプリミティブ型には、5 つの型が存在する。<br />
そのうち、基本データを表す 3 つを挙げてみよう。
</p>
<ul>
<li><dfn>Boolean</dfn></li>
<li><dfn>Number</dfn></li>
<li><dfn>String</dfn></li>
</ul>
<p>
これらがどのようなデータなのかは説明不要だろう。
</p>
<p>
プリミティブということに、違和感を感じる人は多いと思う。<br />
というのも、<dfn>Boolean</dfn>, <dfn>Number</dfn>, <dfn>String</dfn> の 3 つの型は、<br />
オブジェクトとして、良く知られているからだ。
</p>
<a href="http://fireball.loafer.jp/kes/ecmascript/js-basic-primitives.html">続きを読む</a>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/ecmascript/js-basic-primitives.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/ecmascript/js-basic-primitives.html" />
		<published>2008-06-30T23:06:00+09:00</published>
		<title type="html"><![CDATA[基本データを表すプリミティブ型]]></title>
		<updated>2008-06-30T23:06:00+09:00</updated>
	</entry>
	<entry>
		<author>
			<name>kes</name>
			<uri>http://loafer.jp</uri>
		</author>
		<category term="JavaScript" scheme="http://fireball.loafer.jp/kes/ecmascript/" />
		<content type="html">
<![CDATA[
<p>
JavaScript のあらゆる値には、その種類を表す型がある。<br />
型は、大きく 2 つの総称型に分けることができる。<br />
それは、オブジェクト型とプリミティブ型である。<br />
JavaScript にもプリミティブ型が存在するのだ。
</p>
<p>
オブジェクト型は、値の集合を表す。<br />
オブジェクト型の値（以下、オブジェクト）は連想配列（Hash）であり、<br />
任意の文字列のキーに任意の値を関連付けることができる。<br />
オブジェクトに関連付けれらたキーを、プロパティと呼ぶ。
</p>
<p>
プロパティが自由に変更できるため、オブジェクトは可変である。<br />
オブジェクトは参照型であるため、<br />
代入を行っても、オブジェクトが複製されることはなく、<br />
同一のオブジェクトが参照される。
</p>
<p>
それに対して、プリミティブ型は、基本となるデータそのものを表す。<br />
プリミティブ型の値（以下、プリミティブ値）は、<br />
オブジェクトと異なり、プロパティを持つことはできず、<br />
具体的な型に応じた、単一の値のみを保持している。
</p>
<p>
プリミティブ値は、データの最小単位であるため、その値は不変である。
</p>
<p>
通常の用途では、これらのデータ型を意識することはほとんどないが、<br />
言語的には、これらは明確に区別されている。
</p>
]]>
		</content>
		<id>http://fireball.loafer.jp/kes/ecmascript/js-types.html</id>
		<link rel="alternate" type="text/html" href="http://fireball.loafer.jp/kes/ecmascript/js-types.html" />
		<published>2008-06-28T21:12:02+09:00</published>
		<title type="html"><![CDATA[JavaScript のデータ型]]></title>
		<updated>2008-06-28T21:12:02+09:00</updated>
	</entry>

</feed>