<?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"
	>

<channel>
	<title>::低溫烘焙::</title>
	<atom:link href="http://doublekai.org/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://doublekai.org/blog</link>
	<description>自然‧原味</description>
	<pubDate>Tue, 04 Aug 2009 09:54:37 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>好一個SSL認證網站</title>
		<link>http://doublekai.org/blog/?p=1081</link>
		<comments>http://doublekai.org/blog/?p=1081#comments</comments>
		<pubDate>Tue, 04 Aug 2009 09:54:37 +0000</pubDate>
		<dc:creator>sankai</dc:creator>
		
		<category><![CDATA[雜碎唸]]></category>

		<guid isPermaLink="false">http://doublekai.org/blog/?p=1081</guid>
		<description><![CDATA[
ssl網站的網址應該是https:://開頭的吧=_=
]]></description>
			<content:encoded><![CDATA[<p><a href="http://doublekai.org/blog/wp-content/uploads/2009/08/e5a5bde4b880e5808bssle5ae89e585a8e8aa8de8ad89e7b6b2e7ab99.png"><img class="alignnone size-full wp-image-1082" title="e5a5bde4b880e5808bssle5ae89e585a8e8aa8de8ad89e7b6b2e7ab99" src="http://doublekai.org/blog/wp-content/uploads/2009/08/e5a5bde4b880e5808bssle5ae89e585a8e8aa8de8ad89e7b6b2e7ab99.png" alt="" width="427" height="448" /></a></p>
<p>ssl網站的網址應該是https:://開頭的吧=_=</p>
]]></content:encoded>
			<wfw:commentRss>http://doublekai.org/blog/?feed=rss2&amp;p=1081</wfw:commentRss>
		</item>
		<item>
		<title>Kohana Captcha module - securimage</title>
		<link>http://doublekai.org/blog/?p=1065</link>
		<comments>http://doublekai.org/blog/?p=1065#comments</comments>
		<pubDate>Wed, 20 May 2009 15:37:01 +0000</pubDate>
		<dc:creator>sankai</dc:creator>
		
		<category><![CDATA[Kohana]]></category>

		<category><![CDATA[程式語言]]></category>

		<guid isPermaLink="false">http://doublekai.org/blog/?p=1065</guid>
		<description><![CDATA[Well...Maybe it's an unnecessary library in Kohana,but I still try to make it be module.
The original source from http://www.phpcaptcha.org/,so It's GNU LESSER GENERAL PUBLIC LICENSE
呃…或許這個模組在Kohana是多餘的，但是我還是把他做出來了= =，他一樣是用http://www.phpcaptcha.org/的原始碼修改的，所以授權一樣是LGPL
Usage Sample:

class Welcome_Controller extends Controller &#123;
	public function __construct&#40;&#41;
	&#123;
		parent::__construct&#40;&#41;;
	&#125;
	public function index&#40;&#41;
	&#123;
		// Load Securimage library
		$this-&#62;securimage = new Securimage;
&#160;
		// Form submitted
		if &#40;$_POST&#41;
		&#123;
			$imageCode = $this-&#62;input-&#62;post&#40;'imageCode'&#41;;
			echo $this-&#62;securimage-&#62;getCode&#40;&#41;;
			if &#40;$this-&#62;securimage-&#62;check&#40;$imageCode&#41;==true&#41;
			&#123;
				echo '&#60;p style=&#34;color:green&#34;&#62;Good answer!&#60;/p&#62;';
			&#125;
			else
			&#123;
				echo '&#60;p style=&#34;color:red&#34;&#62;Wrong answer!&#60;/p&#62;';
			&#125;
		&#125;
&#160;
		// Show [...]]]></description>
			<content:encoded><![CDATA[<p>Well...Maybe it's an unnecessary library in Kohana,but I still try to make it be module.<br />
The original source from http://www.phpcaptcha.org/,so It's GNU LESSER GENERAL PUBLIC LICENSE<br />
呃…或許這個模組在Kohana是多餘的，但是我還是把他做出來了= =，他一樣是用http://www.phpcaptcha.org/的原始碼修改的，所以授權一樣是LGPL<br />
Usage Sample:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Welcome_Controller <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Load Securimage library</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">securimage</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Securimage<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Form submitted</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$imageCode</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imageCode'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">securimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">securimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">check</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$imageCode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'&lt;p style=&quot;color:green&quot;&gt;Good answer!&lt;/p&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'&lt;p style=&quot;color:red&quot;&gt;Wrong answer!&lt;/p&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Show form</span>
		<span style="color: #990000;">echo</span> form<span style="color: #339933;">::</span><span style="color: #004000;">open</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">echo</span> html<span style="color: #339933;">::</span><span style="color: #004000;">image</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'image/securimage'</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">echo</span> form<span style="color: #339933;">::</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'imageCode'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">echo</span> form<span style="color: #339933;">::</span><span style="color: #004000;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Check'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">echo</span> form<span style="color: #339933;">::</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// End Welcome Controller</span></pre></div></div>

<p><span id="more-1065"></span><br />
Image Controller</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Image_Controller <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> securimage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">securimage</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Securimage<span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">securimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Download:<a href="http://doublekai.org/files/securimage.rar">securimage module</a></p>
]]></content:encoded>
			<wfw:commentRss>http://doublekai.org/blog/?feed=rss2&amp;p=1065</wfw:commentRss>
		</item>
		<item>
		<title>國軍青年日報網站</title>
		<link>http://doublekai.org/blog/?p=1058</link>
		<comments>http://doublekai.org/blog/?p=1058#comments</comments>
		<pubDate>Sat, 16 May 2009 17:34:56 +0000</pubDate>
		<dc:creator>sankai</dc:creator>
		
		<category><![CDATA[雜碎唸]]></category>

		<guid isPermaLink="false">http://doublekai.org/blog/?p=1058</guid>
		<description><![CDATA[話說...我從google新聞看著看著無意間連到這個網站，而且他相當在乎使用者的感覺，所以做了一個很貼心的投票，如下圖：

呃...至少也要考慮一下其它瀏覽器的使用者吧/__\
接著我看見他的頁尾資訊：

現在我懷疑政府機構的案子，外包條件中的「無障礙網頁」，是把圖片貼上去就可以了嗎XD
]]></description>
			<content:encoded><![CDATA[<p>話說...我從google新聞看著看著無意間連到這個網站，而且他相當在乎使用者的感覺，所以做了一個很貼心的投票，如下圖：<br />
<a href="http://doublekai.org/blog/wp-content/uploads/2009/05/break_02.png"><img src="http://doublekai.org/blog/wp-content/uploads/2009/05/break_02.png" alt="" title="break_02" width="500" height="371" class="alignnone size-full wp-image-1060" /></a></p>
<p>呃...至少也要考慮一下其它瀏覽器的使用者吧/__\</p>
<p>接著我看見他的頁尾資訊：<br />
<a href="http://doublekai.org/blog/wp-content/uploads/2009/05/break_01.png"><img src="http://doublekai.org/blog/wp-content/uploads/2009/05/break_01-300x98.png" alt="" title="break_01" width="300" height="98" class="alignnone size-medium wp-image-1059" /></a></p>
<p>現在我懷疑政府機構的案子，外包條件中的「無障礙網頁」，是把圖片貼上去就可以了嗎XD</p>
]]></content:encoded>
			<wfw:commentRss>http://doublekai.org/blog/?feed=rss2&amp;p=1058</wfw:commentRss>
		</item>
		<item>
		<title>filectime 和 filemtime 的差異</title>
		<link>http://doublekai.org/blog/?p=1049</link>
		<comments>http://doublekai.org/blog/?p=1049#comments</comments>
		<pubDate>Wed, 13 May 2009 15:17:09 +0000</pubDate>
		<dc:creator>sankai</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[程式語言]]></category>

		<guid isPermaLink="false">http://doublekai.org/blog/?p=1049</guid>
		<description><![CDATA[最近會使用到「取得檔案最後修改的時間」，從PHP手冊發現有兩個功能描述幾乎一模一樣的函式filectime()與filemtime，當然很自然的好奇倒底是差在哪邊，所以就用G大仙查了一下，很慶幸在「這篇討論文」有找到由coopster所提出的解答:)，而且還特別說明了fileatime這個函式

fileatime

The atime of a file is supposed to change whenever the data blocks of a file are being read. This can be costly performancewise when an application regularly accesses a very large number of files or directories. Some Unix filesystems can be mounted with atime updates disabled to increase the performance of such applications; USENET [...]]]></description>
			<content:encoded><![CDATA[<p>最近會使用到「取得檔案最後修改的時間」，從PHP手冊發現有兩個功能描述幾乎一模一樣的函式filectime()與filemtime，當然很自然的好奇倒底是差在哪邊，所以就用G大仙查了一下，很慶幸在「<a href="http://www.webmasterworld.com/forum88/2070.htm">這篇討論文</a>」有找到由coopster所提出的解答:)，而且還特別說明了fileatime這個函式<br />
<span id="more-1049"></span><br />
<strong>fileatime</strong></p>
<p>
The atime of a file is supposed to change whenever the data blocks of a file are being read. This can be costly performancewise when an application regularly accesses a very large number of files or directories. Some Unix filesystems can be mounted with atime updates disabled to increase the performance of such applications; USENET news spools are a common example. On such filesystems this function will be useless.</p>
<p>(無論這個檔案是否正被讀取，atime會不斷去取得檔案最後存取的時間，但這可能會佔去大量的系統資源，一些UNIX的檔案系統會將此函式設定無效來增加應用程式的效能)</p>
<p><strong>filectime</strong></p>
<p>
In most Unix filesystems, a file is considered changed when its inode data is changed; that is, when the permissions, owner, group, or other metadata from the inode is updated. Note also that in some Unix texts the ctime of a file is referred to as being the creation time of the file. This is wrong. There is no creation time for Unix files in most Unix filesystems.<br />
(當檔案的權限被異動時，就會更新檔案的最後修改時間，注意，有些時候ctime被拿來當做檔案的建立時間，這是錯誤的，在大部分的UNIX系統檔案沒有所謂的建立時間)
</p>
<p><strong>filemtime</strong></p>
<p>
This function returns the time when the data blocks of a file were being written to, that is, the time when the content of the file was changed.<br />
(只有當檔案的被異動後，也就是資料區塊被寫入時，才會更新檔案的最後修改時間)</p>
]]></content:encoded>
			<wfw:commentRss>http://doublekai.org/blog/?feed=rss2&amp;p=1049</wfw:commentRss>
		</item>
		<item>
		<title>Native</title>
		<link>http://doublekai.org/blog/?p=1026</link>
		<comments>http://doublekai.org/blog/?p=1026#comments</comments>
		<pubDate>Wed, 13 May 2009 00:10:04 +0000</pubDate>
		<dc:creator>liaotzukai</dc:creator>
		
		<category><![CDATA[native]]></category>

		<guid isPermaLink="false">http://doublekai.org/blog/?p=1026</guid>
		<description><![CDATA[經由 ClassScript 核心檔所提供的 Native() 方法來指定欲擴充的類型，並呼叫 Prototype() 方法來實作，便可讓我們可以快速的為原生類型提供更便利的使用方法。
舉例說明，一般我們可能會遇到將字串轉換成數字以便計算，這時我們通常會透過 parseInt() 方法來轉換，但是或許你會想使用更簡單的介面，像是 "123".toInt() 的方式，這時我們便可以透過 Native 的來擴充 String 原生類別。

Native&#40;&#34;String&#34;&#41;.Prototype&#40;&#123;
    toInt: function&#40;&#41;&#123;
        return parseInt&#40;this&#41;;
    &#125;
&#125;&#41;;

這時候只要是屬於字串類型的變數，便具有toInt()可供呼叫。

var str = &#34;12&#34;;
str + 34 // print &#34;1234&#34;;
str.toInt&#40;&#41; + 34; // print 46

PS. 當原生類型已經存在的方法，並不會被實作出來(已經有了何必再做呢ˊ_ˋ)
]]></description>
			<content:encoded><![CDATA[<p>經由 ClassScript 核心檔所提供的 Native() 方法來指定欲擴充的類型，並呼叫 Prototype() 方法來實作，便可讓我們可以快速的為原生類型提供更便利的使用方法。</p>
<p>舉例說明，一般我們可能會遇到將字串轉換成數字以便計算，這時我們通常會透過 parseInt() 方法來轉換，但是或許你會想使用更簡單的介面，像是 "123".toInt() 的方式，這時我們便可以透過 Native 的來擴充 String 原生類別。</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Native<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;String&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Prototype</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    toInt<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> parseInt<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>這時候只要是屬於字串類型的變數，便具有toInt()可供呼叫。</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> str <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;12&quot;</span><span style="color: #339933;">;</span>
str <span style="color: #339933;">+</span> <span style="color: #CC0000;">34</span> <span style="color: #006600; font-style: italic;">// print &quot;1234&quot;;</span>
str.<span style="color: #660066;">toInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">34</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// print 46</span></pre></div></div>

<p>PS. 當原生類型已經存在的方法，並不會被實作出來(已經有了何必再做呢ˊ_ˋ)</p>
]]></content:encoded>
			<wfw:commentRss>http://doublekai.org/blog/?feed=rss2&amp;p=1026</wfw:commentRss>
		</item>
		<item>
		<title>ClassScript</title>
		<link>http://doublekai.org/blog/?p=1018</link>
		<comments>http://doublekai.org/blog/?p=1018#comments</comments>
		<pubDate>Tue, 12 May 2009 16:29:02 +0000</pubDate>
		<dc:creator>liaotzukai</dc:creator>
		
		<category><![CDATA[ClassScript]]></category>

		<category><![CDATA[core]]></category>

		<guid isPermaLink="false">http://doublekai.org/blog/?p=1018</guid>
		<description><![CDATA[ClassScript是一個模擬Java寫法的JavaScript Lib，目的是讓開發者能再JavaScript的環境中，用Java宣告Class類似語法來宣告JavaScript的Class。但是基於JavaScript本身的語法限制，所以不可避免有些部份無法實作出來，但是還是能提供相當直覺的宣告方式，目前實作出來的語法介面為下：

Package - 並非實際的將class包起來，而是使用物件來存放Class的參照，比較像是命名空間
Class - 類別的宣告，並提供Extends、Implments兩個語法介面的實作
Interface - 本質上也是個類別，只是提供Interface關鍵字來模擬，在嘗試實作new時會拋出例外
Abstract.Class  - 本質上也是個類別，只是提供Abstract關鍵字來模擬，在嘗試實作new時會拋出例外
Super - 父類別參照，透過Super來呼叫superclass的參照
Static - 靜態屬性，在Class的建構式中，使用Static.來宣告Class的靜態方法
Native - 針對 JavaScript原生類別作為擴充的特別類別宣告方法

開發感想：
由於JavaScript是個弱型別與直譯式的語法，所以是否要實作Interface與Abstract.Class的令我蠻猶豫的，宣告了一個完全沒有實作的方法的介面或抽象類別，再給一個Class去實作、繼承，在JavaScript感覺作了兩次工，光宣告介面就感覺像多此一舉，而且研究目前有實坐出Class的JavaScript Lib，幾乎也都只有Class，其他似乎沒必要。但既然說要模擬Java的宣告方式，就索性得把這些方法都做出來了。
]]></description>
			<content:encoded><![CDATA[<p>ClassScript是一個模擬Java寫法的JavaScript Lib，目的是讓開發者能再JavaScript的環境中，用Java宣告Class類似語法來宣告JavaScript的Class。但是基於JavaScript本身的語法限制，所以不可避免有些部份無法實作出來，但是還是能提供相當直覺的宣告方式，目前實作出來的語法介面為下：</p>
<ul>
<li>Package - 並非實際的將class包起來，而是使用物件來存放Class的參照，比較像是命名空間</li>
<li>Class - 類別的宣告，並提供Extends、Implments兩個語法介面的實作</li>
<li>Interface - 本質上也是個類別，只是提供Interface關鍵字來模擬，在嘗試實作new時會拋出例外</li>
<li>Abstract.Class  - 本質上也是個類別，只是提供Abstract關鍵字來模擬，在嘗試實作new時會拋出例外</li>
<li>Super - 父類別參照，透過Super來呼叫superclass的參照</li>
<li>Static - 靜態屬性，在Class的建構式中，使用Static.來宣告Class的靜態方法</li>
<li>Native - 針對 JavaScript原生類別作為擴充的特別類別宣告方法</li>
</ul>
<p>開發感想：</p>
<p>由於JavaScript是個弱型別與直譯式的語法，所以是否要實作Interface與Abstract.Class的令我蠻猶豫的，宣告了一個完全沒有實作的方法的介面或抽象類別，再給一個Class去實作、繼承，在JavaScript感覺作了兩次工，光宣告介面就感覺像多此一舉，而且研究目前有實坐出Class的JavaScript Lib，幾乎也都只有Class，其他似乎沒必要。但既然說要模擬Java的宣告方式，就索性得把這些方法都做出來了。</p>
]]></content:encoded>
			<wfw:commentRss>http://doublekai.org/blog/?feed=rss2&amp;p=1018</wfw:commentRss>
		</item>
		<item>
		<title>Firebug Lite</title>
		<link>http://doublekai.org/blog/?p=1004</link>
		<comments>http://doublekai.org/blog/?p=1004#comments</comments>
		<pubDate>Sun, 03 May 2009 02:33:12 +0000</pubDate>
		<dc:creator>sankai</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[程式語言]]></category>

		<guid isPermaLink="false">http://doublekai.org/blog/?p=1004</guid>
		<description><![CDATA[原本以為FireBug只有在好用的firefox才有的plugin，今天我二哥說…官方早就有一個叫Firebug Lite。囧rz...我竟然這麼晚才發現，害我每次在Firefox跑很順的網頁，在IE跑不出來，然後這個笨IE的錯誤訊息又令人抓狂。(不過通常在firefox正常的，ie不正常的原因往往都只有一個，就是在物件陣列裡了一個逗號)

var obj = {     
     param1: '參數1',
     param2: '參數2', //最後多了一個逗號，在IE就會出錯
}

anyway...這個是常常裡到才會記得的ie問題，但是如果不是這個原因就頭大了/__\，不過Firebug Lite的安裝方法比較不同，他並不是像firefox的插件，而是用javascript所模擬的，安裝方法就是直接在網頁中載入官方所提供的「firebug-lite.js」，載入的方式有三種：


//第一種是直接以絕對網頁的方式指定官網的firebug lib網址：
http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js


//第二種是把firebug-lite.js下載回來自己的電腦，再載入：
myproject/js/firebug-lite-compressed.js


//第三種是把官方提供的快速鍵，加入到我的最愛
Firebug Lite as bookmarklet
Drag the following link to your bookmark toolbar and use Firebug Lite on any page:
&#160;
Firebug Lite &#60;= 在這個連結按右鍵，加至我的最愛

唯一美中不足的地方就是他好像沒有檢視browser送出資料的功能(post,get所傳送的值)=..=
不過重點是在ie能抓蟲就好了 \  /
]]></description>
			<content:encoded><![CDATA[<p>原本以為FireBug只有在好用的firefox才有的plugin，今天我二哥說…官方早就有一個叫<a href="http://getfirebug.com/lite.html">Firebug Lite</a>。囧rz...我竟然這麼晚才發現，害我每次在Firefox跑很順的網頁，在IE跑不出來，然後這個笨IE的錯誤訊息又令人抓狂。(不過通常在firefox正常的，ie不正常的原因往往都只有一個，就是在物件陣列裡了一個逗號)</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">var obj = {     
     param1: '參數1',
     param2: '參數2', //最後多了一個逗號，在IE就會出錯
}</pre></div></div>

<p>anyway...這個是常常裡到才會記得的ie問題，但是如果不是這個原因就頭大了/__\，不過Firebug Lite的安裝方法比較不同，他並不是像firefox的插件，而是用javascript所模擬的，安裝方法就是直接在網頁中載入官方所提供的「firebug-lite.js」，載入的方式有三種：<br />
<span id="more-1004"></span></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">//第一種是直接以絕對網頁的方式指定官網的firebug lib網址：
http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">//第二種是把firebug-lite.js下載回來自己的電腦，再載入：
myproject/js/firebug-lite-compressed.js</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">//第三種是把官方提供的快速鍵，加入到我的最愛
Firebug Lite as bookmarklet
Drag the following link to your bookmark toolbar and use Firebug Lite on any page:
&nbsp;
Firebug Lite &lt;= 在這個連結按右鍵，加至我的最愛</pre></div></div>

<p>唯一美中不足的地方就是他好像沒有檢視browser送出資料的功能(post,get所傳送的值)=..=<br />
不過重點是在ie能抓蟲就好了 \  /</p>
]]></content:encoded>
			<wfw:commentRss>http://doublekai.org/blog/?feed=rss2&amp;p=1004</wfw:commentRss>
		</item>
		<item>
		<title>哪一種程式語言好？</title>
		<link>http://doublekai.org/blog/?p=998</link>
		<comments>http://doublekai.org/blog/?p=998#comments</comments>
		<pubDate>Sat, 25 Apr 2009 13:18:09 +0000</pubDate>
		<dc:creator>sankai</dc:creator>
		
		<category><![CDATA[雜碎唸]]></category>

		<guid isPermaLink="false">http://doublekai.org/blog/?p=998</guid>
		<description><![CDATA[哪一種程式語言比較好呢？
通常會提出這個問題的是一個剛想踏入暗黑程式界的初心者程式設計師
希望在一開始就能夠選擇對的路，拜對師門。我的經驗告訴我，不論你
選擇哪個門派，唯有一種結果是肯定的
「絛絛道路通爆肝」
「欲成高手，必先爆肝」
通常討論或提到這個問題所得到的回應，大多是各語言擁立的支持者
開始互相抨擊對方有多爛，然後誇讚自己有多好。
這不知道算不算是一種迷失呢，深陷在追求強化效能語言漩渦裡

企管有一本相當有名的小說叫「目標」，作者是高德拉特，一個TOC制約法創始人。
至於什麼是TOC法則，可以到圖書館借閱這本書，讓自己觀念獲得翻新。
或許用TOC來比喻我接下來要講的內容有點不符合，但我覺得這和TOC
想要傳達的意思很像，如果有TOC高手發現我說錯了，也煩請指點糾正。
你必需想想程式最終的目的是什麼？
「寫出一個系統，讓N個使用者使用」
假設有兩種新的程式語言叫OGC和ORZ，一個效能超高，學習曲線高
一個效能普普，學習曲線低，每年有10000名投入這兩種語言的學習者
如下表：
			OGC	　 ORZ
===================================
效能(反應）  	 0.3s      1.5s
易學度　　　   	　 2%     10%
每年精通程式高手     200p　 1000p
伺服可負荷量      10000kp   200kp
高手分享資源           3%     15%
====================================
p=人,kp=萬人
接下來使用不同程式語言開發的可能實際情況
－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－
選擇了 OGC　做為開發的情況
－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－
OGC工程師：
		老闆，我一個人開發有點吃力，再請一個工程師好嗎？
老闆：
		我再用多請一位好了(因為高手少，花了3.8萬請了一位)
老闆：
		我們的系統(網站)用OGC開發的，有超高的效能，只要在0.3就能完
		成你要的功能。
廠商：
		我才不管理你們用啥東開發勒，只要我需求的功能有出來就好
		但不能太慢，在反應2秒之內，都能接受。我的客戶群大概有
		100萬人
OGC工程師：
		我是個OGC程式高手，但新進來的菜鳥還要慢慢的教他
		真是有夠麻煩的啦！每天都加班，媽的我不想做了
開發過程中…
老闆：
		幹，我請來的GC的程式設計師說他家母狗生小貓，所以他不幹了
		我去2222人力銀行徵才，丟出一個月4萬薪資，沒半個來應徵。
廠商：
		啥小，你說你工程師突然離職了，所以專案還要延二個月？！
		關我屁事，把你的違約金準備好吧
老闆：
		（老闆對著新的工程師微笑）你準備肝爆吧！
－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－
選擇了 ORZ　做為開發的情況
－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－
ORZ工程師：
		老闆，我一個人開發有點吃力，再請一個工程師好嗎？
老闆：
		我再用多請一位好了(因為高手多，花了3萬請了一位)
老闆：
		我們的系統(網站)用ORZ開發的，每個功能大概要1.5秒才能完成
廠商：
		我才不管理你們用啥東開發勒，只要我需求的功能有出來就好
		但不能太慢，在反應2秒之內，都能接受。我的客戶群大概有
		100萬人
ORZ工程師：
		我是個ORZ程式高手，新進來的菜鳥基本程度還不錯，一點就懂
		而且網路上的學習資源很多，丟給他學習就好了。兩個人開發速度
		還滿快的，今天進度也達到了，下班後來去泡溫泉=v=
開發過程中…
老闆：
		你的專案將在下禮拜完成，聽說你還想要再做另外一個專案是嗎？
廠商：
		嗯，接下來這個案子我希望也要在六個月完成，可以嗎？
老闆：
		沒問題=v=
＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝
情況分析：	  
1.在老闆有限的資源與預算，可以與你共事的高手工程師能有幾個？
	若你是萬中選一的高手，那麼你就準備爆肝吧！
2.系統或網站的使用者人數有多少？
	若這個系統（網站）曾經的最大同時使用者為68萬人
	那麼你的程式能負荷1000萬人有意義嗎？
3.效能的0.3s和1.5s對使用者有感受差嗎(假設使用者在於2s都能接受)
	使用者會因為你快了1.2s而對這個系統產生好感嗎？
	通常會在意這種東西，也只有該死的工程師不是嗎？
＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝	
好像有點偏離主題了(跳tone跳真大＝.＝)
如果你正苦惱底到要選擇哪一種語言，你可以用下列幾點做參考：
1.語言最好選擇偏向容易學習的。為什麼這麼說呢，當你先學習容易學的程式，你會有一定的基礎
　這樣甘果想要轉偏難的語言，就不會那麼吃力。就好比網路遊戲你不會一開始就去高等怪區打怪吧？
　穩趴的，而且容易學習程式語言的學習者會偏多，高手多，資源也就偏多（好練咩）
2.應專心於一種語言，然後學習如何兩其它程式做橋接結合的部分技術，而不是什麼都學而不精
　因為我信相任何一個程式語言高手都是對於他們的選擇下過功夫的（爆肝過)，就像網路遊戲有人
　練逆天型的，超難練，但練起來就爆強(雙關語)XD
3.以你目前可得到最多資源的做為選擇，假設你已經有前輩是某程式高手，而且願意帶你的話
　那你可以考量一開始就跳至學習偏難的程式語言。不過呀…電影有名言「人一定要靠自己」
 [...]]]></description>
			<content:encoded><![CDATA[<p>哪一種程式語言比較好呢？</p>
<p>通常會提出這個問題的是一個剛想踏入暗黑程式界的初心者程式設計師<br />
希望在一開始就能夠選擇對的路，拜對師門。我的經驗告訴我，不論你<br />
選擇哪個門派，唯有一種結果是肯定的</p>
<p>「絛絛道路通爆肝」<br />
「欲成高手，必先爆肝」</p>
<p>通常討論或提到這個問題所得到的回應，大多是各語言擁立的支持者<br />
開始互相抨擊對方有多爛，然後誇讚自己有多好。</p>
<p>這不知道算不算是一種迷失呢，深陷在追求強化效能語言漩渦裡<br />
<span id="more-998"></span><br />
企管有一本相當有名的小說叫「目標」，作者是高德拉特，一個TOC制約法創始人。<br />
至於什麼是TOC法則，可以到圖書館借閱這本書，讓自己觀念獲得翻新。</p>
<p>或許用TOC來比喻我接下來要講的內容有點不符合，但我覺得這和TOC<br />
想要傳達的意思很像，如果有TOC高手發現我說錯了，也煩請指點糾正。</p>
<p>你必需想想程式最終的目的是什麼？</p>
<p>「寫出一個系統，讓N個使用者使用」</p>
<p>假設有兩種新的程式語言叫OGC和ORZ，一個效能超高，學習曲線高<br />
一個效能普普，學習曲線低，每年有10000名投入這兩種語言的學習者<br />
如下表：</p>
<p>			OGC	　 ORZ<br />
===================================<br />
效能(反應）  	 0.3s      1.5s<br />
易學度　　　   	　 2%     10%<br />
每年精通程式高手     200p　 1000p<br />
伺服可負荷量      10000kp   200kp<br />
高手分享資源           3%     15%<br />
====================================<br />
p=人,kp=萬人</p>
<p>接下來使用不同程式語言開發的可能實際情況</p>
<p>－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br />
選擇了 OGC　做為開發的情況<br />
－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br />
OGC工程師：<br />
		老闆，我一個人開發有點吃力，再請一個工程師好嗎？<br />
老闆：<br />
		我再用多請一位好了(因為高手少，花了3.8萬請了一位)<br />
老闆：<br />
		我們的系統(網站)用OGC開發的，有超高的效能，只要在0.3就能完<br />
		成你要的功能。<br />
廠商：<br />
		我才不管理你們用啥東開發勒，只要我需求的功能有出來就好<br />
		但不能太慢，在反應2秒之內，都能接受。我的客戶群大概有<br />
		100萬人<br />
OGC工程師：<br />
		我是個OGC程式高手，但新進來的菜鳥還要慢慢的教他<br />
		真是有夠麻煩的啦！每天都加班，媽的我不想做了</p>
<p>開發過程中…</p>
<p>老闆：<br />
		幹，我請來的GC的程式設計師說他家母狗生小貓，所以他不幹了<br />
		我去2222人力銀行徵才，丟出一個月4萬薪資，沒半個來應徵。<br />
廠商：<br />
		啥小，你說你工程師突然離職了，所以專案還要延二個月？！<br />
		關我屁事，把你的違約金準備好吧<br />
老闆：<br />
		（老闆對著新的工程師微笑）你準備肝爆吧！<br />
－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br />
選擇了 ORZ　做為開發的情況<br />
－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－<br />
ORZ工程師：<br />
		老闆，我一個人開發有點吃力，再請一個工程師好嗎？<br />
老闆：<br />
		我再用多請一位好了(因為高手多，花了3萬請了一位)<br />
老闆：<br />
		我們的系統(網站)用ORZ開發的，每個功能大概要1.5秒才能完成<br />
廠商：<br />
		我才不管理你們用啥東開發勒，只要我需求的功能有出來就好<br />
		但不能太慢，在反應2秒之內，都能接受。我的客戶群大概有<br />
		100萬人<br />
ORZ工程師：<br />
		我是個ORZ程式高手，新進來的菜鳥基本程度還不錯，一點就懂<br />
		而且網路上的學習資源很多，丟給他學習就好了。兩個人開發速度<br />
		還滿快的，今天進度也達到了，下班後來去泡溫泉=v=</p>
<p>開發過程中…</p>
<p>老闆：<br />
		你的專案將在下禮拜完成，聽說你還想要再做另外一個專案是嗎？<br />
廠商：<br />
		嗯，接下來這個案子我希望也要在六個月完成，可以嗎？<br />
老闆：<br />
		沒問題=v=</p>
<p>＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝<br />
情況分析：	  </p>
<p>1.在老闆有限的資源與預算，可以與你共事的高手工程師能有幾個？<br />
	若你是萬中選一的高手，那麼你就準備爆肝吧！</p>
<p>2.系統或網站的使用者人數有多少？<br />
	若這個系統（網站）曾經的最大同時使用者為68萬人<br />
	那麼你的程式能負荷1000萬人有意義嗎？</p>
<p>3.效能的0.3s和1.5s對使用者有感受差嗎(假設使用者在於2s都能接受)<br />
	使用者會因為你快了1.2s而對這個系統產生好感嗎？<br />
	通常會在意這種東西，也只有該死的工程師不是嗎？</p>
<p>＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝	</p>
<p>好像有點偏離主題了(跳tone跳真大＝.＝)<br />
如果你正苦惱底到要選擇哪一種語言，你可以用下列幾點做參考：</p>
<p>1.語言最好選擇偏向容易學習的。為什麼這麼說呢，當你先學習容易學的程式，你會有一定的基礎<br />
　這樣甘果想要轉偏難的語言，就不會那麼吃力。就好比網路遊戲你不會一開始就去高等怪區打怪吧？<br />
　穩趴的，而且容易學習程式語言的學習者會偏多，高手多，資源也就偏多（好練咩）</p>
<p>2.應專心於一種語言，然後學習如何兩其它程式做橋接結合的部分技術，而不是什麼都學而不精<br />
　因為我信相任何一個程式語言高手都是對於他們的選擇下過功夫的（爆肝過)，就像網路遊戲有人<br />
　練逆天型的，超難練，但練起來就爆強(雙關語)XD</p>
<p>3.以你目前可得到最多資源的做為選擇，假設你已經有前輩是某程式高手，而且願意帶你的話<br />
　那你可以考量一開始就跳至學習偏難的程式語言。不過呀…電影有名言「人一定要靠自己」<br />
  而且我覺得大部分的高手工程師都有大頭症</p>
<p>4.等專攻的語言精熟之後，要學習橋接其它語言技術。這樣才能拿雙手劍呀！XD，不過若搞到三刀流<br />
　就有點辛苦了</p>
<p>5.一個海賊團裡面要有航海士、廚師、醫生、音樂家，所以要多認識一些不同技術的朋友或合作隊友<br />
　像是應用程式、WEB網頁開發、CSS設計師、網管、flashAS師</p>
<p>6.尊重別人的專業，肯定自己的專業，武器不在多，夠利就好。<br />
  你覺得一把鋒利的阿嬤牌菜刀和一把生鏽的貴夫人劍，哪個砍人比較傷呢？</p>
<p>你用憤慨眼神看著我，我知道你最後還是想問，倒底要學哪一種程式語言啦！？<br />
好吧…如果你不嫌棄我的選擇，我建議一開始可以先從PHP開始學習，效能或許沒其它語言好<br />
但是他的確是個相當易學的程式，資源也相當多<br />
若你是喜歡挑戰高難度的玩家，那請直接向C語言往違大的髮線前進吧(我朋友的髮線又往後移動了)</p>
]]></content:encoded>
			<wfw:commentRss>http://doublekai.org/blog/?feed=rss2&amp;p=998</wfw:commentRss>
		</item>
		<item>
		<title>ClassScript：類別的Extends(繼承)與Implements(實作)</title>
		<link>http://doublekai.org/blog/?p=975</link>
		<comments>http://doublekai.org/blog/?p=975#comments</comments>
		<pubDate>Sat, 25 Apr 2009 11:00:19 +0000</pubDate>
		<dc:creator>liaotzukai</dc:creator>
		
		<category><![CDATA[ClassScript]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[程式語言]]></category>

		<category><![CDATA[ClassScirpt]]></category>

		<guid isPermaLink="false">http://doublekai.org/blog/?p=975</guid>
		<description><![CDATA[物件導向的核心價值來自於繼承的機制，當然ClassScript少不了實作此方法。
首先我們來宣告父類別

Abstract.Class&#40;&#34;Animal&#34;&#41;&#40;function&#40;&#41;&#123;
    var name
&#160;
    this.constructor = function&#40;n&#41;&#123;
        name = n
    &#125;
&#160;
    this.getName = function&#40;&#41;&#123;
        return name;
    &#125;
&#160;
    this.setName = function&#40;n&#41;&#123;
     [...]]]></description>
			<content:encoded><![CDATA[<p>物件導向的核心價值來自於繼承的機制，當然ClassScript少不了實作此方法。</p>
<p>首先我們來宣告父類別</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Abstract.<span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Animal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">constructor</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> n
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066;">name</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> n<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>接下來宣告子類別</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Dog&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #003366; font-weight: bold;">Extends</span><span style="color: #009900;">&#40;</span>Animal<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">showName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>建立Dog物件，並呼叫方法</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> d <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Dog<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Bob&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>d.<span style="color: #660066;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//→ 顯示 &quot;Bob&quot;</span>
d.<span style="color: #660066;">showName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//→ 顯示  &quot;&quot;(null) 私有屬性不會被繼承,所以沒有定義name變數</span></pre></div></div>

<p><span id="more-975"></span></p>
<p>ClassScript也實作了Implements方法，與Java不同的是，介面不一定要為純抽象的，介面中的方法如果有定義，那類別就直接實作了介面的方法，除非你有重新定義方法，否則他將會直接以介面的方法作為實際的內容。</p>
<p>這部分雖然可以寫成限制必須為Interface的類別才能實作，但JavaScript並沒有強制變數型態，限制這樣的做法反而會失去彈性與簡單性。</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Interface<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myInterface'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    run<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'the '</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' is running!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Animal&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">Implements</span><span style="color: #009900;">&#40;</span>myInterface<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">constructor</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> n
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> n<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> ani1 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Animal<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Pig&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
ani1.<span style="color: #660066;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// → 顯示 'the Pig is running!'</span></pre></div></div>

<p>這裡有的必須注意的地方就是，介面中的方法不能操作私有屬性，因為這是JavaScript的限制，目前還沒找到比較好的作法，所以目前最好的方式就是使用公開屬性。不然就使用覆寫的方式。一個介面的方法如果被覆寫了，他所在的變數區域就可以取得類別的私有成員。</p>
]]></content:encoded>
			<wfw:commentRss>http://doublekai.org/blog/?feed=rss2&amp;p=975</wfw:commentRss>
		</item>
		<item>
		<title>ClassScript：靜態、私有與公開屬性</title>
		<link>http://doublekai.org/blog/?p=961</link>
		<comments>http://doublekai.org/blog/?p=961#comments</comments>
		<pubDate>Sat, 25 Apr 2009 10:27:51 +0000</pubDate>
		<dc:creator>liaotzukai</dc:creator>
		
		<category><![CDATA[ClassScript]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[程式語言]]></category>

		<guid isPermaLink="false">http://doublekai.org/blog/?p=961</guid>
		<description><![CDATA[續上一篇「像Java一樣的寫法來宣告JavaScript的Class」簡單的介紹Class的宣告方式，這篇針對屬性的特性做說明，ClassScript除了實作靜態屬性，也實作了封裝的特性，雖然不是百分百模擬其特性，但在使用上就像是封裝的特性。接下來一一說明使用方法：
1.私有屬性 - 使用 var 宣告，直接使用 變數 操作

Class&#40;&#34;Animal&#34;&#41;&#40;function&#40;&#41;&#123;
    var name
&#160;
    this.constructor = function&#40;n&#41;&#123;
        name = n
    &#125;
&#160;
    this.getName = function&#40;&#41;&#123;
        return name;
    &#125;
&#160;
    this.setName [...]]]></description>
			<content:encoded><![CDATA[<p>續上一篇「<a href="http://doublekai.org/?p=933" target="_blank">像Java一樣的寫法來宣告JavaScript的Class</a>」簡單的介紹Class的宣告方式，這篇針對屬性的特性做說明，ClassScript除了實作靜態屬性，也實作了封裝的特性，雖然不是百分百模擬其特性，但在使用上就像是封裝的特性。接下來一一說明使用方法：</p>
<p>1.私有屬性 - 使用 <strong>var</strong> 宣告，直接使用 <strong>變數</strong> 操作</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Animal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">constructor</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> n
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066;">name</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> n<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> oneAnimal <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Animal<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;狗&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>oneAnimal.<span style="color: #660066;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//→ 顯示 '狗'</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>oneAnimal.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//→ 顯示 'undefined' (未定義)</span></pre></div></div>

<p><span id="more-961"></span></p>
<p>2.公開屬性 -  使用 <strong>this.</strong> 宣告，使用 <strong>this.</strong> 作變數操作</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Animal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">constructor</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> n
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> n<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> twoAnimal <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Animal<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;貓&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>twoAnimal.<span style="color: #660066;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//→ 顯示 '貓'</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>twoAnimal.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//→ 顯示 '貓'</span></pre></div></div>

<p>3.靜態屬性 - 使用 <strong>Static.</strong> 宣告，使用<strong>this.Statc.</strong> 或 <strong>類別名稱.變數名稱.</strong>作變數操作</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Animal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    Static.<span style="color: #660066;">count</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">constructor</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> n
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">Static</span>.<span style="color: #660066;">count</span> <span style="color: #339933;">+=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">getName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setName</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>n<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> n<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>Animal.<span style="color: #660066;">count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//→ 0</span>
<span style="color: #003366; font-weight: bold;">var</span> oneAnimal <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Animal<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;狗&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>Animal.<span style="color: #660066;">count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//→ 1</span>
<span style="color: #003366; font-weight: bold;">var</span> twoAnimal <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Animal<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;貓&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>Animal.<span style="color: #660066;">count</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//→ 2</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://doublekai.org/blog/?feed=rss2&amp;p=961</wfw:commentRss>
		</item>
	</channel>
</rss>
