婷婷久久五月天,草草久久久无码国产专区,狼狼综合久久久久综合网http://www.shnenglu.com/momoxiao/zh-cnThu, 08 May 2025 21:27:59 GMTThu, 08 May 2025 21:27:59 GMT60doubanclaim5b86c10222094ec4http://www.shnenglu.com/momoxiao/archive/2013/08/15/202556.html小默小默Thu, 15 Aug 2013 06:22:00 GMThttp://www.shnenglu.com/momoxiao/archive/2013/08/15/202556.html

小默 2013-08-15 14:22 發(fā)表評論
]]>
中文字號、磅和像素對照關(guān)系http://www.shnenglu.com/momoxiao/archive/2012/02/18/165936.html小默小默Sat, 18 Feb 2012 15:05:00 GMThttp://www.shnenglu.com/momoxiao/archive/2012/02/18/165936.htmlhttp://www.shnenglu.com/momoxiao/comments/165936.htmlhttp://www.shnenglu.com/momoxiao/archive/2012/02/18/165936.html#Feedback0http://www.shnenglu.com/momoxiao/comments/commentRss/165936.htmlhttp://www.shnenglu.com/momoxiao/services/trackbacks/165936.html


本文介紹中文字號、磅(pt)和像素(px)的對照關(guān)系,方便大家設(shè)計網(wǎng)頁時參考合適的字號,一般網(wǎng)頁正文字體為12px到16px,相當(dāng)于9-12磅字號大小,標(biāo)題文字可以稍大一點,具體參見下文表格字體大小,本文內(nèi)容來源于網(wǎng)絡(luò)匯總,做了點補充,如有錯誤,歡迎指出。

一、基本單位概念

單位中文名稱轉(zhuǎn)換
inch英寸1英寸=2.54厘米
cm厘米 
pt磅或點數(shù),是point簡稱1pt=1/72(英寸)
px像素,是pix簡稱 
   

二、中文字號大小、磅和像素對照關(guān)系

下表參照顯示器96dbi(每英寸點數(shù))顯示進行換算結(jié)果。比如:6.5pt = 6.5 * 1/72 * 96 = 8.6px,像素肯定不能出現(xiàn)小數(shù)點的,一般是取小顯示。下表字體已經(jīng)按照各行所代表的字號大小進行顯示。

字號磅(pt)像素(px)
小六6.58px
六號7.510px
小五912px
五號10.514px
小四1216px
四號1418px
小三1520px
三號1621px
小二1824px
二號2229px
小一2432px
一號2634px
小初3648px
初號4256px


小默 2012-02-18 23:05 發(fā)表評論
]]>
Session cookies for web applicationshttp://www.shnenglu.com/momoxiao/archive/2011/10/09/157836.html小默小默Sat, 08 Oct 2011 23:14:00 GMThttp://www.shnenglu.com/momoxiao/archive/2011/10/09/157836.htmlhttp://www.shnenglu.com/momoxiao/comments/157836.htmlhttp://www.shnenglu.com/momoxiao/archive/2011/10/09/157836.html#Feedback0http://www.shnenglu.com/momoxiao/comments/commentRss/157836.htmlhttp://www.shnenglu.com/momoxiao/services/trackbacks/157836.htmlSession cookies for web applications [http://lwn.net/Articles/283383/]
By Jake Edge
May 21, 2008

Two weeks ago on this page, we reported on some Wordpress vulnerabilities that were caused by incorrectly generating authentication cookies. The article was a bit light on details about such cookies, so this follow-up hopes to remedy that. In addition, Steven Murdoch, who discovered both of the holes, recently presented a paper on a new cookie technique that provides some additional safeguards over other schemes.

兩周前在此頁上,我們報道了由不正確生成的身份驗證 cookies 引起的一些 Wordpress 漏洞。那篇文檔對這些 cookies 的細(xì)節(jié)描述略少,這篇后續(xù)的文章希望能解決這個問題。另外,發(fā)現(xiàn)這些漏洞的 Steven Murdoch,最近發(fā)表了篇關(guān)于一種新的 cookie 技術(shù)的文章,文章提供了其他方案之`上`的一些額外保護措施。

HTTP is a stateless protocol which means that any application that wishes to track multiple requests as a single session must provide its own way to link those requests. This is typically done through cookies, which are opaque blobs of data that are stored by browsers. Cookies are sent to the browser as part of an HTTP response, usually after some kind of authentication is successful. The browser associates the cookie with the URL of the site so that it can send the cookie value back to the server on each subsequent request.

HTTP 是一種無狀態(tài)的協(xié)議,這意味著任何希望跟蹤多個請求作為單個會話的應(yīng)用程序,必須提供自己的方式來鏈接這些請求。這通常通過 cookies 來完成,cookies 是瀏覽器存儲的不透明的數(shù)據(jù)塊。通常,在某種身份認(rèn)證成功后,cookies 被作為一個 HTTP 響應(yīng)的一部分發(fā)送給瀏覽器。瀏覽器把 cookie 和對應(yīng)網(wǎng)站的 URL 關(guān)聯(lián)起來,以便它可以在每個后續(xù)請求中回送 cookie 值到服務(wù)器。

Servers can then use the value as a key into some kind of persistent storage so that all requests that contain that cookie value are treated as belonging to a particular session. In particular, it represents that the user associated with that session has correctly authenticated. The cookie lasts until it expires or is deleted by the user. When that happens, the user must re-authenticate to get a new cookie which also starts a new session. Users find this annoying if it happens too frequently, so expirations are often quite long.

然后,服務(wù)器可以`用某種持久性存儲的鍵`使用該值,使得所有包含該 cookie 值的請求,被視為屬于同一個特定會話。特別是,它代表和該會話關(guān)聯(lián)的那個已經(jīng)正確通過身份驗證的用戶。一個 cookie 一直存在,直到過期或被用戶刪除。此時,用戶必須重新進行身份驗證,獲取一個新 cookie,同時開始一個新會話。如果它發(fā)生的過于頻繁,會讓用戶感到惱人,所以到期時間通常相當(dāng)長。

If the user explicitly logs out of the application, any server-side resources that are being used to store state information can be freed, but that is often not the case. Users will generally just close their browser (or tab) while still being logged in. It is also convenient for users to be allowed multiple concurrent sessions, generally from multiple computers, which will cause the number of sessions stored to be larger, perhaps much larger, than the number of users.

如果用戶顯式地登出應(yīng)用程序,任何用來存儲狀態(tài)信息的服務(wù)器端資源會被釋放,但情況經(jīng)常不是這樣。用戶通常只是關(guān)閉他們的瀏覽器(或標(biāo)簽頁),當(dāng)仍在登錄狀態(tài)時。這也允許用戶方便地,從不同的計算機上使用多個并發(fā)會話。這將導(dǎo)致存儲更大的會話數(shù)量,也許比用戶數(shù)量大許多。

Applications could restrict the number of sessions allowed by a user, or ratchet the expiration value way down, but they typically do not for user convenience. This allows for a potential denial of service when an attacker creates so many sessions that the server runs out of persistent storage. For this reason, stateless session cookies [PDF][http://prisms.cs.umass.edu/~kevinfu/papers/webauth_tr.pdf] were created.

應(yīng)用程序可以限制允許一個用戶使用的會話數(shù),或者``,但它們通常不方便用戶使用。這允許一個潛在的拒絕服務(wù),當(dāng)一個攻擊者創(chuàng)建太多會話,以至于服務(wù)器用完持久性存儲時。出于這個原因,無狀態(tài)會話 cookies 被創(chuàng)建。

Stateless session cookies store all of the state information in the cookie itself, so that the server need not keep anything in the database, filesystem, or memory. The data in the cookie must be encoded in such a way that they cannot be forged, otherwise attackers could create cookies that allow them access they should not have. This is essentially where Wordpress went wrong. By not implementing stateless session cookies correctly, a valid cookie for one user could be modified into a valid cookie for a different user.

無狀態(tài)會話 cookies 把所有狀態(tài)信息存儲到 cookie 本身,使服務(wù)器不需要在數(shù)據(jù)庫、文件系統(tǒng)或內(nèi)存中保存任何信息。Cookie 中的數(shù)據(jù)必須以不能被偽造的方式編碼,否則攻擊者可以創(chuàng)建允許他們訪問不應(yīng)該訪問內(nèi)容的 cookies 。實際上這就是 Wordpress 出問題的地方。由于沒有正確使用無狀態(tài)會話 cookies ,一個用戶的有效 cookie 可以被修改成另一個不同用戶的有效 cookie 。

A stateless session cookie has the state data and expiration "in the clear" followed by a secure hash (SHA-256 for example) of those same values along with a key known only by the server. When the server receives the cookie value, it can calculate the hash and if it matches, proceed to use the state information. Because the secret is not known, an attacker cannot create their own cookies with values of their choosing.

一個無狀態(tài)的會話 cookie 有狀態(tài)數(shù)據(jù)和明確的到期時間,后跟一個安全哈希值(例如 SHA-256),該哈希值和只有服務(wù)器知道的一個鍵`對應(yīng)`。當(dāng)服務(wù)器接收到 cookie 值,會計算哈希值,如果匹配,繼續(xù)使用其中的狀態(tài)信息。由于這個密鑰是未知的,攻擊者不能使用他們選擇的值創(chuàng)建自己的 cookies 。

The other side of that coin is that an attacker can create spoofed cookies if they know the secret. Murdoch wanted to extend the concept such that even getting access to the secret, through a SQL injection or other web application flaw, would not feasibly allow an attacker to create a spoofed cookie. The result is hardened stateless session cookies [PDF][http://www.cl.cam.ac.uk/~sjm217/papers/protocols08cookies.pdf].

硬幣的另一面是,如果攻擊者知道密鑰,可以創(chuàng)建欺騙性的 cookies 。Murdoch 希望擴展概念,使得通過 SQL 注入或其它 web 應(yīng)用漏洞訪問密鑰后,攻擊者也無法創(chuàng)建一個欺騙性的 cookie。結(jié)果就是強化的無狀態(tài)會話 cookies 。

The basic idea behind the scheme is to add an additional field to stateless session cookies that corresponds to an authenticator generated when an account is first set up. This authenticator is generated from the password at account creation by iteratively calculating the cryptographic hash of the password and a long salt value.

該方案背后的基本思路是,給無狀態(tài)會話 cookie 增加一個額外的字段,這個字段和賬戶首次設(shè)置時生成的一個`身份驗證器`對應(yīng)。身份驗證器由創(chuàng)建賬戶時的密碼生成,生成方法是,迭代計算密碼的加密哈希和一個長 salt 值。

Salt is a random string—usually just a few characters long—that is added to a password before it gets hashed, then stored with the password in the clear. It is used to eliminate the use of rainbow tables to crack passwords. Hardened stateless session cookies use a 128-bit salt value, then repeatedly calculate HASH(prev|salt), where prev is the password the first time through and the hash value from the previous calculation on each subsequent iteration.

Salt 是一個隨機字符串——通常只有幾個字符長——它在被計算哈希值前添加到密碼中,然后以明文形式和密碼一起存儲。它是用來杜絕使用彩虹表破解密碼的。`硬化`的無狀態(tài)會話 cookies 使用128位 salt 值,然后迭代計算 HASH(prev|salt) , 其中 prev 在第一次迭代時是密碼,在以后每次迭代中是上次計算的 hash 值。

The number of iterations is large, 256 for example, but not a secret. Once that value is calculated, it is hashed one last time, without the salt, and then stored in the user table as the authenticator. When the cookie value is created after a successful authentication, only the output of the iterative hash itself is placed in the cookie, not the authenticator that is stored in the database. Cookie verification then must do the standard stateless session cookie hash verification, to ensure that the values have not been manipulated, then hash the value in the cookie to verify against authenticator in the database.

迭代次數(shù)是個大的值,例如256,但這不是保密的。值被計算出來后,再不使用 salt 哈希一次,然后作為身份驗證器存儲到用戶表中。當(dāng) cookie 通過一次成功認(rèn)證被創(chuàng)建后,只有輸出的迭代哈希值被保存在 cookie 中,而不保存數(shù)據(jù)庫中的身份驗證器。Cookie 驗證必須進行標(biāo)準(zhǔn)的無狀態(tài)會話 cookie 哈希驗證,來確保值沒有被修改過,然后哈希 cookie 中的值和數(shù)據(jù)庫中的身份驗證器對比。

If it sounds complicated, it is; the performance of doing 256 hashes is also an issue, but it does protect against the secret key being lost. Because an attacker cannot calculate a valid authenticator value to put in the cookie (doing so would require breaking SHA-256), they cannot create their own spoofed cookies.

如果這聽起來很復(fù)雜,確實;進行256次哈希的性能也是一個問題,但它確實能避免密鑰丟失。因為攻擊者無法計算一個有效的用戶驗證器放進 cookie 中(這樣做需要突破 SHA-256),所以他們不能創(chuàng)建自己的欺騙 cookie 。

While it is not clear that the overhead of all of these hash calculations is warranted, it is an interesting extension to the stateless session cookie scheme. In his paper, Murdoch mentions some variations that could be used to further increase the security of the technique.

目前尚不清楚所有這些哈希計算的開銷是否有必要,這是一個擴展無狀態(tài)會話 cookie 的有趣方案。在他的文章中,Murdoch 提到了一些可以進一步提高該技術(shù)安全性的變化。


---
后面沒看明白。
無狀態(tài)會話 cookie 中的密鑰可能被攻擊者獲取,authenticator 為什么不能被攻擊者獲取?獲取這兩個東西的難度有區(qū)別么?

---
TODO
| hash salt
| 彩虹表

小默 2011-10-09 07:14 發(fā)表評論
]]>
django, CSRF token missing or incorrect http://www.shnenglu.com/momoxiao/archive/2011/10/03/157443.html小默小默Mon, 03 Oct 2011 14:56:00 GMThttp://www.shnenglu.com/momoxiao/archive/2011/10/03/157443.htmlhttp://www.shnenglu.com/momoxiao/comments/157443.htmlhttp://www.shnenglu.com/momoxiao/archive/2011/10/03/157443.html#Feedback0http://www.shnenglu.com/momoxiao/comments/commentRss/157443.htmlhttp://www.shnenglu.com/momoxiao/services/trackbacks/157443.html
CSRF token missing or incorrect
--
1 在 templete 中, 為每個 POST form 增加一個 {% csrf_token %} tag. 如下:
<form>
    {% csrf_token %}
</form>
2 在 view 中, 使用 django.template.RequestContext 而不是 Context.
render_to_response, 默認(rèn)使用 Context. 需要改成 RequestContext.
導(dǎo)入 class:
from django.template import RequestContext
給 render_to_response 增加一個參數(shù):
def your_view(request):
    ...
    return render_to_response('template.html',
          your_data,
          context_instance=RequestContext(request)
    )


小默 2011-10-03 22:56 發(fā)表評論
]]>
'JavaScript DOM 編程藝術(shù)' 第三章 DOM 例子http://www.shnenglu.com/momoxiao/archive/2011/09/26/156794.html小默小默Sun, 25 Sep 2011 21:05:00 GMThttp://www.shnenglu.com/momoxiao/archive/2011/09/26/156794.htmlhttp://www.shnenglu.com/momoxiao/comments/156794.htmlhttp://www.shnenglu.com/momoxiao/archive/2011/09/26/156794.html#Feedback0http://www.shnenglu.com/momoxiao/comments/commentRss/156794.htmlhttp://www.shnenglu.com/momoxiao/services/trackbacks/156794.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    
<style>
        body 
{
            color
: white;
            background-color
: black;
        
}
        p 
{
            color
: yellow;
            font-family
: "arial", sans-serif;
            font-size
: 1.2em;
        
}

        .special 
{
            font-style
: italic;
        
}
        h2.special 
{
            text-transform
: uppercase;
        
}

        #purchases 
{
            border
: 1px solid white;
            background-color
: #333;
            color
: #ccc;
            padding
: 1em;
        
}
        #purchases li 
{
            font-weight
: bold;
        
}
    
</style>
    
<meta http-equiv="content-type" content="text/html; charset=utf-8">
    
<title>Shopping list</title>
</head>
<body>
    
<h1>What to buy</h1>
    
<title="a gentle reminder">Don't forget to buy this stuff.</p>
    
<ul id="purchases">
        
<li>A tin of beans</li>
        
<li>Cheese</li>
        
<li>Milk</li>
    
</ul>

    
<class="special">This paragraph has the special class</p>
    
<h2 class="special">So does this headline</h2>

    
<script>
    var println 
= function(arg) {
        
if (arg)
            document.write(arg);
        document.write(
"<br />");
    }

    println(
"getElementById():");
    println(
"id purchases: " + document.getElementById("purchases"));
    println(
"innerText: " + document.getElementById("purchases").innerText);
    println();

    println(
"getElementsByTagName():")
    li_items 
= document.getElementsByTagName("li");
    println(
"tag li: " + li_items);
    println(
"length: " + li_items.length);
    
for (var i = 0; i < li_items.length; i++) {
        println(i 
+ "" + document.getElementsByTagName("li")[i].innerText);
    }
    println();

    println(
"with \"*\" :");
    println(
"all tags: " + document.getElementsByTagName("*").length);
    println();

    println(
"combine ById and ByTagName - get tags in a id: ")
    
var shopping = document.getElementById("purchases");
    
var items = shopping.getElementsByTagName("*");
    println(
"tag \"*\" in id \"purchases\"" + items.length);
    println();

    println(
"object.getAttribute(attribute) - get title attribute of the objects which tags are p");
    
var tags_p = document.getElementsByTagName("p");
    
for (var i = 0; i < tags_p.length; i++) {
        println(tags_p[i].getAttribute(
"title"));
    }
    println();

    println(
"object.setAttribute(attribute, value) - set title attribute of the object which id is purchases");
    
var shopping = document.getElementById("purchases");
    shopping.setAttribute(
"title""a list of goods");
    println(shopping.getAttribute(
"title"));

    
</script>
</body>
</html>


小默 2011-09-26 05:05 發(fā)表評論
]]>
HTML xmlns 屬性http://www.shnenglu.com/momoxiao/archive/2011/09/26/156789.html小默小默Sun, 25 Sep 2011 16:41:00 GMThttp://www.shnenglu.com/momoxiao/archive/2011/09/26/156789.htmlhttp://www.shnenglu.com/momoxiao/comments/156789.htmlhttp://www.shnenglu.com/momoxiao/archive/2011/09/26/156789.html#Feedback0http://www.shnenglu.com/momoxiao/comments/commentRss/156789.htmlhttp://www.shnenglu.com/momoxiao/services/trackbacks/156789.html
HTML xmlns 屬性
xmlns 屬性可以在文檔中定義一個或多個可供選擇的命名空間. 該屬性可以放置在文檔內(nèi)任何元素的開始標(biāo)簽中. 該屬性的值類似于 URL, 它定義了一個命名空間, 瀏覽器會將此命名空間用于該屬性所在元素內(nèi)的所有內(nèi)容.
例如, 如果需要使用符合 XML 規(guī)范的 XHTML 文檔, 則應(yīng)該在文檔中的 <html> 標(biāo)簽中至少使用一個 xmlns 屬性, 以指定整個文檔所使用的主要命名空間.
<html xmlns="http://www.w3.org/1999/xhtml">

--
http://www.w3school.com.cn/tags/tag_prop_xmlns.asp

--
TODO XML
~              


小默 2011-09-26 00:41 發(fā)表評論
]]>
html doctype declarationhttp://www.shnenglu.com/momoxiao/archive/2011/09/25/156783.html小默小默Sun, 25 Sep 2011 15:22:00 GMThttp://www.shnenglu.com/momoxiao/archive/2011/09/25/156783.htmlhttp://www.shnenglu.com/momoxiao/comments/156783.htmlhttp://www.shnenglu.com/momoxiao/archive/2011/09/25/156783.html#Feedback0http://www.shnenglu.com/momoxiao/comments/commentRss/156783.htmlhttp://www.shnenglu.com/momoxiao/services/trackbacks/156783.html
HTML <!DOCTYPE> Declaration
--
Definition and Usage
The doctype declaration should be the very first thing in an HTML document, before the <html> tag.
The doctype declaration is not an HTML tag; it is an instruction to the web browser about what version of the markup language the page is written in.
The doctype declaration refers to a Document Type Defination(DTD). The DTD specifies the rules for the markup language, so that the browsers render the content correctly.
--
Doctype Avalable in the W3C Recommendations
XHTML 1.1
This DTD is equal to XHTML 1.0 Strict, but allows you to add modules (for examp.e to provide ruby support for East-Asian languages).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
--
http://www.w3schools.com/tags/tag_doctype.asp


小默 2011-09-25 23:22 發(fā)表評論
]]>
phpmyadminhttp://www.shnenglu.com/momoxiao/archive/2011/09/24/156717.html小默小默Sat, 24 Sep 2011 14:09:00 GMThttp://www.shnenglu.com/momoxiao/archive/2011/09/24/156717.htmlhttp://www.shnenglu.com/momoxiao/comments/156717.htmlhttp://www.shnenglu.com/momoxiao/archive/2011/09/24/156717.html#Feedback0http://www.shnenglu.com/momoxiao/comments/commentRss/156717.htmlhttp://www.shnenglu.com/momoxiao/services/trackbacks/156717.html
# yum install phpmyadmin

Config:
# vim /usr/share/phpMyAdmin/config.inc.php 
$cfg['blowfish_secret'] = 'colorfulgreen'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Run:
# /etc/init.d/mysqld start
# service httpd start


小默 2011-09-24 22:09 發(fā)表評論
]]>
[zz]JavaScript 的 new, 好久不見啊http://www.shnenglu.com/momoxiao/archive/2011/09/24/156668.html小默小默Fri, 23 Sep 2011 20:54:00 GMThttp://www.shnenglu.com/momoxiao/archive/2011/09/24/156668.htmlhttp://www.shnenglu.com/momoxiao/comments/156668.htmlhttp://www.shnenglu.com/momoxiao/archive/2011/09/24/156668.html#Feedback0http://www.shnenglu.com/momoxiao/comments/commentRss/156668.htmlhttp://www.shnenglu.com/momoxiao/services/trackbacks/156668.htmlhttp://ued.taobao.com/blog/2007/05/15/%E4%BD%A0%E7%9C%9F%E7%9A%84%E4%BC%9A%E5%86%99javascript%E5%90%97%EF%BC%9F/
--

JavaScript 的 new, 好久不見啊

原文: JavaScript, We Hardly new Ya --Douglas Crockford。

JavaScript是一門基于原型的語言,但它卻擁有一個 new 操作符使得其看起來象一門經(jīng)典的面對對象語言。那樣也迷惑了程序員們,導(dǎo)致一些有問題的編程模式。

其實你永遠(yuǎn)不需要在JavaScript使用 new Object()。用字面量的形式{}去取代吧。

同理,不要使用 new Array() ,而代之以字面量[]。JavaScript中的數(shù)組并不象Java中的數(shù)組那樣工作的,使用類似Java的語法只會讓你糊涂。

同理不用使用 new Number, new String, 或者 new Boolean。這些的用法只會產(chǎn)生無用的類型封裝對象。就直接使用簡單的字面量吧。

不要使用 new Function 去創(chuàng)建函數(shù)對象。用函數(shù)表達(dá)式更好。比如:

frames[0].onfocus = new Function(“document.bgColor=’antiquewhite’”)

更好的寫法是:

frames[0].onfocus = function () {document.bgColor = ‘antiquewhite’;};

第二種形式讓腳本編譯器更快的看到函數(shù)主體,于是其中的語法錯誤也會更快被檢測出來。有時候程序員使用 new Function 是因為他們沒有理解內(nèi)部函數(shù)是如何工作的。

selObj.onchange = new Function(“dynamicOptionListObjects["+
dol.index+"].change(this)”);

如果我們讓用字符串做函數(shù)體,編譯器不能看到它們。如果我們用字符串表達(dá)式做函數(shù)體,我們同樣也看不到它們。更好的方式就是不要盲目編程。通過制造一個返回值為函數(shù)的函數(shù)調(diào)用,我們可以明確的按值傳遞我們想要綁定的值。這允許我們在循環(huán)中初始化一系列 selObj 對象。

selObj.onchange = function (i) {
return function () {
dynamicOptionListObjects[i].change(this);

};
}(dol.index);

直接對一個函數(shù)使用new永遠(yuǎn)不是一個好主意。比如, new function 對構(gòu)造新對象沒有提供什么優(yōu)勢。

myObj = new function () {
this.type = ‘core’;
};

更好的方式是使用對象字面量,它更輕巧,更快捷。

myObj = {
type: ‘core’
};

假如我們需要創(chuàng)建的對象包含的方法需要訪問私有變量或者函數(shù),更好的方式仍然是避免使用new.var foo = new function() {
function processMessages(message) {
alert(“Message: ” + message.content);
}
this.init = function() {
subscribe(“/mytopic”, this, processMessages);
}
}
通過使用 new 去調(diào)用函數(shù),對象會持有一個無意義的原型對象。這只會浪費內(nèi)存而不會帶來任何好處。如果我們不使用new,我們就不用在對象鏈維護一個無用的prototype對象。所以我們可以用()來正確的調(diào)用工廠函數(shù)。var foo = function () {
function processMessages(message) {
alert(“Message: ” + message.content);
}
return {
init: function () {
subscribe(“/mytopic”, this, processMessages);
}
};
}();
所以原則很簡單: 唯一應(yīng)該要用到new操作符的地方就是調(diào)用一個古老的構(gòu)造器函數(shù)的時候。當(dāng)調(diào)用一個構(gòu)造器函數(shù)的時候,是強制要求使用new的。有時候可以來new一下, 有的時候還是不要了吧。



小默 2011-09-24 04:54 發(fā)表評論
]]>
JavaScript 兩個等號 三個等號http://www.shnenglu.com/momoxiao/archive/2011/09/24/156665.html小默小默Fri, 23 Sep 2011 18:16:00 GMThttp://www.shnenglu.com/momoxiao/archive/2011/09/24/156665.htmlhttp://www.shnenglu.com/momoxiao/comments/156665.htmlhttp://www.shnenglu.com/momoxiao/archive/2011/09/24/156665.html#Feedback1http://www.shnenglu.com/momoxiao/comments/commentRss/156665.htmlhttp://www.shnenglu.com/momoxiao/services/trackbacks/156665.html=== 用來進行嚴(yán)格比較,不是同類型直接false



小默 2011-09-24 02:16 發(fā)表評論
]]>
伊人久久大香线蕉精品| 婷婷久久香蕉五月综合加勒比| 青青青国产精品国产精品久久久久| 精品久久久久中文字| 一本色道久久综合狠狠躁| 蜜桃麻豆www久久| 无码AV中文字幕久久专区| 久久精品无码一区二区app| 亚洲午夜久久久久久久久久| 久久99精品久久久久久齐齐| jizzjizz国产精品久久| 久久精品aⅴ无码中文字字幕不卡 久久精品成人欧美大片 | 亚洲国产精品久久| 亚洲国产一成人久久精品| 久久伊人影视| 精品久久久久久国产三级| 久久久国产精品福利免费| 无码久久精品国产亚洲Av影片 | 狠狠色丁香久久综合五月| 亚洲色大成网站WWW久久九九| 久久久久九国产精品| 91精品国产91久久久久久青草| 久久精品国产精品亚洲下载| 亚洲精品乱码久久久久久蜜桃 | 奇米影视7777久久精品| 国产99久久精品一区二区| 国内精品欧美久久精品| 亚洲国产日韩欧美综合久久| 久久久久女人精品毛片| 国产成人精品久久亚洲高清不卡| 无码人妻少妇久久中文字幕| 久久精品国产亚洲AV麻豆网站| 伊人久久综在合线亚洲2019| 欧美日韩精品久久久久| 国产精品一区二区久久精品| 久久综合狠狠综合久久97色| 久久精品国产亚洲AV无码麻豆| 久久国产综合精品五月天| 三上悠亚久久精品| 久久久久久国产精品美女| 久久久av波多野一区二区|