﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-heavensay-随笔分类-web-front</title><link>http://www.blogjava.net/heavensay/category/53972.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 29 Oct 2013 13:40:08 GMT</lastBuildDate><pubDate>Tue, 29 Oct 2013 13:40:08 GMT</pubDate><ttl>60</ttl><item><title>jQuery分析纪要</title><link>http://www.blogjava.net/heavensay/archive/2013/10/29/405733.html</link><dc:creator>heavensay</dc:creator><author>heavensay</author><pubDate>Tue, 29 Oct 2013 12:18:00 GMT</pubDate><guid>http://www.blogjava.net/heavensay/archive/2013/10/29/405733.html</guid><wfw:comment>http://www.blogjava.net/heavensay/comments/405733.html</wfw:comment><comments>http://www.blogjava.net/heavensay/archive/2013/10/29/405733.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/heavensay/comments/commentRss/405733.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/heavensay/services/trackbacks/405733.html</trackback:ping><description><![CDATA[&nbsp; &nbsp; &nbsp; &nbsp;本文是对jQuery源码分析的简单纪要。<br /><br /><strong style="font-size: 8pt;">jQuery相关对象内存图</strong><br /><img src="http://www.blogjava.net/images/blogjava_net/heavensay/web-front/jquery-structure.jpg" width="588" height="561" alt="" /><br /><br /><br />&nbsp; &nbsp;&nbsp;<strong>jQuery代码分析纪要：</strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1、 jQuery一加载进来，就执行匿名函数，进行jQuery的初始化工作，定义jQuery的功能，最后暴露出jQuery和$变量给用户使用。<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->(<span style="color: #0000FF; ">function</span>(&nbsp;window,&nbsp;undefined&nbsp;)&nbsp;{<br /><img src="http://www.blogjava.net/Images/dot.gif" alt="" /><img src="http://www.blogjava.net/Images/dot.gif" alt="" /><br />window.jQuery&nbsp;=&nbsp;window.$&nbsp;=&nbsp;jQuery<br />})(&nbsp;window&nbsp;);</div><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2、 jQuery功能扩展函数Extend<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->jQuery.extend&nbsp;=&nbsp;jQuery.fn.extend&nbsp;=&nbsp;<span style="color: #0000FF; ">function</span>()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;<img src="http://www.blogjava.net/Images/dot.gif" alt="" /><img src="http://www.blogjava.net/Images/dot.gif" alt="" /><br />}</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jQuery提供了2个供用户扩展的函数jQuery.extend和jQuery.fn.extend。</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jQuery.extend 用于扩展jQuery自身方法，如jQuery.ajax, jQuery.getJSON等，jQuery.fn.extend则是用于扩展jQuery(...)的方法，从上面的内存图中可以看出，经过jQuery包装后的dom元素，在其原型链上会拥有jQuery.fn.extend扩展的方法。</div><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3、 jQuery函数，就是我们平常$('#id')所执行的函数，返回包装过的dom元素<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->&nbsp; &nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;Define&nbsp;a&nbsp;local&nbsp;copy&nbsp;of&nbsp;jQuery</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;jQuery&nbsp;=&nbsp;<span style="color: #0000FF; ">function</span>(&nbsp;selector,&nbsp;context&nbsp;)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;The&nbsp;jQuery&nbsp;object&nbsp;is&nbsp;actually&nbsp;just&nbsp;the&nbsp;init&nbsp;constructor&nbsp;'enhanced'</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;jQuery.fn.init(&nbsp;selector,&nbsp;context,&nbsp;rootjQuery&nbsp;);<br />&nbsp;&nbsp;&nbsp;&nbsp;},</div><img src ="http://www.blogjava.net/heavensay/aggbug/405733.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/heavensay/" target="_blank">heavensay</a> 2013-10-29 20:18 <a href="http://www.blogjava.net/heavensay/archive/2013/10/29/405733.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Js中Prototype、__proto__、Constructor、Object、Function关系介绍</title><link>http://www.blogjava.net/heavensay/archive/2013/10/20/405440.html</link><dc:creator>heavensay</dc:creator><author>heavensay</author><pubDate>Sun, 20 Oct 2013 15:47:00 GMT</pubDate><guid>http://www.blogjava.net/heavensay/archive/2013/10/20/405440.html</guid><wfw:comment>http://www.blogjava.net/heavensay/comments/405440.html</wfw:comment><comments>http://www.blogjava.net/heavensay/archive/2013/10/20/405440.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/heavensay/comments/commentRss/405440.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/heavensay/services/trackbacks/405440.html</trackback:ping><description><![CDATA[<div style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', Tahoma, Helvetica, sans-serif, 'Microsoft YaHei', Georgia, Helvetica, Arial, sans-serif, 宋体, PMingLiU, serif; font-size: 14px; line-height: 21px;"><div><strong style="font-size: 14px; line-height: 21px;">一 &nbsp; &nbsp;<span style="font-size: 10.5pt; line-height: 1.5;">Prototype、__proto__与</span><span style="font-size: 10.5pt; line-height: 1.5;">Object、Function关系介绍<br /></span></strong><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Function、Object：Js自带的函数对象。</div><div><span style="font-size: 10.5pt; line-height: 1.5;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-size: 10.5pt; line-height: 1.5;">prototype,每一个函数对象都有一个显示的prototype属性,它代表了对象的原型(Function.prototype函数对象是个例外，没有prototype属性)。</span></div><div><span style="font-size: 10.5pt; line-height: 1.5;">&nbsp; &nbsp;&nbsp;</span><span style="font-size: 10.5pt; line-height: 1.5;">&nbsp; &nbsp;&nbsp;</span><span style="font-size: 10.5pt; line-height: 1.5;">__proto__:</span><span style="font-size: 10.5pt; line-height: 1.5;">每个对象都有一个名为__proto__的内部隐藏属性，指向于它所对应的原型对象</span><span style="font-size: 10.5pt; line-height: 1.5;">(chrome、firefox中名称为__proto__，并且可以被访问到)。</span><span style="font-size: 10.5pt; line-height: 1.5;">原型链正是基于__proto__才得以形成(note：不是基于函数对象的属性prototype)。</span></div></div><div style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', Tahoma, Helvetica, sans-serif, 'Microsoft YaHei', Georgia, Helvetica, Arial, sans-serif, 宋体, PMingLiU, serif; font-size: 14px; line-height: 21px;"></div><div style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', Tahoma, Helvetica, sans-serif, 'Microsoft YaHei', Georgia, Helvetica, Arial, sans-serif, 宋体, PMingLiU, serif; font-size: 14px; line-height: 21px;">&nbsp; &nbsp; &nbsp; &nbsp;关于上面提到的函数对象，我们来看以下例子，来说明：<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF; ">var</span>&nbsp;o1&nbsp;=&nbsp;{};<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">var</span>&nbsp;o2&nbsp;=<span style="color: #0000FF; ">new</span>&nbsp;Object();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">function</span>&nbsp;f1(){}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">var</span>&nbsp;f2&nbsp;=&nbsp;<span style="color: #0000FF; ">function</span>(){}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">var</span>&nbsp;f3&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Function('str','console.log(str)');<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f3('aabb');&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">&nbsp;aabb</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;Object:'+<span style="color: #0000FF; ">typeof</span>&nbsp;Object);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">function</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;Function:'+<span style="color: #0000FF; ">typeof</span>&nbsp;Function);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">function</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;o1:'+<span style="color: #0000FF; ">typeof</span>&nbsp;o1);&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">object</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;o2:'+<span style="color: #0000FF; ">typeof</span>&nbsp;o2);&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">object</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;f1:'+<span style="color: #0000FF; ">typeof</span>&nbsp;f1);&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">function</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;f2:'+<span style="color: #0000FF; ">typeof</span>&nbsp;f2);&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">function</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;f3:'+<span style="color: #0000FF; ">typeof</span>&nbsp;f3);&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">function</span></div><ul style="font-size: 14px; line-height: 21px;"><li><span style="font-size: 10.5pt; line-height: 1.5;">通常我们认为o1、o2是对象，即普通对象；f1、f2、f3为函数。</span></li><li><span style="font-size: 10.5pt; line-height: 1.5;">但是其实函数也是对象，是由Function构造的，</span></li><li><span style="font-size: 10.5pt; line-height: 1.5;">f3这种写法就跟对象的创建的写法一样。</span><span style="font-size: 10.5pt; line-height: 1.5;">f1、f2最终也都像f3一样是有Function这个函数构造出来的</span></li><li><span style="font-size: 10.5pt; line-height: 1.5;">f1、f2、f3为函数对象，Function跟Object本身也是函数对象。</span></li></ul>&nbsp; &nbsp;&nbsp;<span style="font-size: 14px; line-height: 21px;">&nbsp; &nbsp;</span><span style="font-size: 10.5pt; line-height: 1.5;">Js中每个对象(null除外)都和另一个对象相关联，</span><span style="font-size: 10.5pt; line-height: 1.5;">通过以下例子跟内存效果图来分析Function、Object、Prototype、__proto__对象</span><span style="font-size: 10.5pt; line-height: 1.5;">间的关系。</span><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">function</span>&nbsp;Animal(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">var</span>&nbsp;&nbsp;anim&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Animal();<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('***********Animal&nbsp;anim&nbsp;proto*****************');<br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;Animal.prototype:'&nbsp;+<span style="color: #0000FF; ">typeof</span>&nbsp;Animal.prototype);&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">object&nbsp;</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('anim.__proto__===Animal.prototype:'+(anim.__proto__===Animal.prototype));&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Animal.__proto__===Function.prototype:'+(Animal.__proto__===Function.prototype));&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Animal.prototype.__proto__===Object.prototype:'+(Animal.prototype.__proto__===Object.prototype));&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('***********Function&nbsp;proto*****************');<br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;Function.prototype:'+<span style="color: #0000FF; ">typeof</span>&nbsp;Function.prototype);&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">function</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;Function.__proto__:'+<span style="color: #0000FF; ">typeof</span>&nbsp;Function.__proto__);&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">function</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;Function.prototype.prototype:'+<span style="color: #0000FF; ">typeof</span>&nbsp;Function.prototype.prototype);&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">undefined</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;Function.prototype.__proto__:'+<span style="color: #0000FF; ">typeof</span>&nbsp;Function.prototype.__proto__);&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">object</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Function.prototype===Function.__proto__:'+(Function.prototype===Function.__proto__));&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span><br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('***********Object&nbsp;proto*****************');<br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;Object.prototype:'+<span style="color: #0000FF; ">typeof</span>&nbsp;Object.prototype);&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">object</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('<span style="color: #0000FF; ">typeof</span>&nbsp;Object.__proto__:'+<span style="color: #0000FF; ">typeof</span>&nbsp;Object.__proto__);&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">function</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Object.prototype.prototype:'+Object.prototype.prototype);&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">undefied</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Object.prototype.__proto__===<span style="color: #0000FF; ">null</span>:'+(Object.prototype.__proto__===<span style="color: #0000FF; ">null</span>));&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">null</span><span style="color: #008000; "><br /></span><br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('***********Function&nbsp;Object&nbsp;&nbsp;proto关系*****************');<br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('Function.prototype===Object.__proto__:'+(Function.prototype===Object.__proto__));&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Function.__proto__===Object.__proto__:'+(Function.__proto__===Object.__proto__));&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Function.prototype.__proto__===Object.prototype:'+(Function.prototype.__proto__===Object.prototype));&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">/*</span><span style="color: #008000; ">********************&nbsp;系统定义的对象Array、Date&nbsp;***************************</span><span style="color: #008000; ">*/</span><br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('**************test&nbsp;Array、Date****************');&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">var</span>&nbsp;array&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Array();<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">var</span>&nbsp;date&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Date();<br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('array.__proto__===Array.prototype:'+(array.__proto__===Array.prototype));&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Array.__proto__===Function.prototype:'+(Array.__proto__===Function.prototype));&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('date.__proto__===Date.prototype:'+(date.__proto__===Date.prototype));&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Date.__proto__===Function.prototype:'+(Date.__proto__===Function.prototype));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span></div><br /><span style="font-size: 8pt; line-height: 1.5;"><strong>Function、Object、Prototype、__proto__内存关系图</strong></span><br /><img src="http://www.blogjava.net/images/blogjava_net/heavensay/web-front/8164530.png" width="631" height="643" alt="" /><br /><br />&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: 14px; line-height: 21px;">上面的内存图跟堆栈结构可以参照文章</span><a href="http://www.cnblogs.com/fool/archive/2010/10/07/1845226.html" style="font-size: 14px; line-height: 21px;">Javascript_01_理解内存分配</a>。<br />&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-size: 14px; line-height: 21px;">堆区图说明：</span><br /><img src="http://www.blogjava.net/images/blogjava_net/heavensay/web-front/35166462.png" width="353" height="237" alt="" />&nbsp;<br /><span style="font-size: 14px; line-height: 21px;">&nbsp; &nbsp; &nbsp;</span><span style="font-family: verdana, 'courier new'; font-size: 14px; line-height: 20px;">&nbsp; &nbsp;</span><span style="font-size: 14px; line-height: 21px;">Function.prototype函数对象图内部表示prototype属性的</span><span style="font-size: 10.5pt; line-height: 1.5;">红色虚框</span><span style="font-size: 10.5pt; line-height: 1.5;">，只是为了说明这个属性不存在。</span></div><div style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', Tahoma, Helvetica, sans-serif, 'Microsoft YaHei', Georgia, Helvetica, Arial, sans-serif, 宋体, PMingLiU, serif; font-size: 14px; line-height: 21px;"><br /><div style="font-size: 14px; line-height: 21px;"><span style="font-size: 10.5pt; line-height: 1.5;">&nbsp; &nbsp;&nbsp;</span><span style="font-size: 10.5pt; line-height: 1.5;">&nbsp; &nbsp;&nbsp;</span><strong style="font-size: 10.5pt; line-height: 1.5;">通过上图Function、Object、Prototype关系图中，可以得出一下几点：</strong></div><div style="font-size: 14px; line-height: 21px;"><ol><li><span style="font-size: 14px; line-height: 21px;">所有对象所有对象，包括函数对象的原型链最终都指向了Object.prototype，而Object.prototype.__proto__===null，原型链至此结束。</span></li><li><span style="font-size: 14px; line-height: 21px;">Animal.prototype是一个普通对象。</span></li><li><span style="font-size: 14px; line-height: 21px;">Object是一个函数对象，也是Function构造的，Object.prototype是一个普通对象。</span></li><li><span style="font-size: 14px; line-height: 21px;">Object.prototype.__type__指向null。</span></li><li><span style="font-size: 14px; line-height: 21px;">Function.prototype是一个函数对象，前面说函数对象都有一个显示的prototype属性，但是Function.prototype却没有prototype属性，即Function.prototype.prototype===undefined，所有Function.prototype函数对象是一个特例，没有prototype属性。</span></li><li><span style="font-size: 14px; line-height: 21px;">Object虽是Function构造的一个函数对象，但是Object.prototype没有指向Function.prototype，即Object.prototype!==Function.prototype。</span></li></ol></div><strong style="font-size: 14px; line-height: 21px;"><br />二 &nbsp; &nbsp;Prototype跟Constructor关系</strong><strong style="font-size: 10.5pt; line-height: 1.5;">介绍</strong><br /><div style="font-size: 14px; line-height: 21px;">&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在 JavaScript 中，每个函数对象都有名为&#8220;prototype&#8221;的属性<span style="font-size: 10.5pt; line-height: 1.5;">(上面提到过Function.prototype函数对象是个例外，没有prototype属性)</span><span style="font-size: 10.5pt; line-height: 1.5;">，用于引用原型对象。此原型对象又有名为&#8220;constructor&#8221;的属性，它反过来引用函数本身。这是一种循环引用（i.e.&nbsp;</span><span style="font-size: 10.5pt; line-height: 1.5;">Animal.prototype.constructor===Animal）。</span></div><div style="font-size: 14px; line-height: 21px;"></div><div style="font-size: 14px; line-height: 21px;"><span style="font-size: 14px; line-height: 21px;">&nbsp; &nbsp;&nbsp;</span><span style="font-size: 14px; line-height: 21px;">&nbsp; &nbsp;&nbsp;</span><span style="font-size: 10.5pt; line-height: 1.5;">通过以下例子跟内存效果图来分析Prototype、constructor</span><span style="font-size: 10.5pt; line-height: 1.5;">间的关系。</span></div><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->&nbsp; &nbsp; console.log('**************constructor****************');&nbsp;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('anim.constructor===Animal:'+(anim.constructor===Animal))&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Animal===Animal.prototype.constructor:'+(Animal===Animal.prototype.constructor))&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Animal.constructor===Function.prototype.constructor:'+(Animal.constructor===Function.prototype.constructor));&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Function.prototype.constructor===Function:'+(Function.prototype.constructor===Function));&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Function.constructor===Function.prototype.constructor:'+(Function.constructor===Function.prototype.constructor));&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span><br />&nbsp;&nbsp;&nbsp;&nbsp;console.log('Object.prototype.constructor===Object:'+(Object.prototype.constructor===Object));&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;console.log('Object.constructor====Function:'+(Object.constructor===Function));&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">true</span></div><br /><strong style="font-size: 14px; line-height: 21px;"><span data-wiz-span="data-wiz-span" style="font-size: 8pt;">&nbsp;prototype、constructor内存关系图(</span><span style="font-size: 8pt; line-height: 1.5;">在Function、Object、Prototype关系图上加入constructor元素</span><span style="font-size: 8pt; line-height: 1.5;">)：</span></strong><br /><img src="http://www.blogjava.net/images/blogjava_net/heavensay/web-front/8199006.png" width="627" height="646" alt="" /><br /><br /><div style="font-size: 14px; line-height: 21px;">&nbsp; &nbsp; &nbsp; &nbsp; 上图中，红色箭头表示函数对象的原型的constructor所指向的对象。</div><div style="font-size: 14px; line-height: 21px;"><div><ol><li><span style="font-size: 14px; line-height: 21px;">注意Object.constructor===Function；本身Object就是Function函数构造出来的 &nbsp; &nbsp; &nbsp; &nbsp;</span></li><li><span style="font-size: 10.5pt; line-height: 1.5;">如何查找一个对象的constructor，就是在该对象的原型链上寻找碰到的第一个constructor属性所指向的对象。</span></li></ol></div><span style="font-size: 14px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif;"><div></div><div><strong>参考：</strong></div><div><a href="http://www.cnblogs.com/fool/category/264215.html" style="font-family: 'Microsoft YaHei UI', 'Microsoft YaHei', SimSun, 'Segoe UI', Tahoma, Helvetica, sans-serif, 'Microsoft YaHei', Georgia, Helvetica, Arial, sans-serif, 宋体, PMingLiU, serif; font-size: 10.5pt; line-height: 1.5;">http://www.cnblogs.com/fool/category/264215.html</a>&nbsp;(javascript原理介绍)</div></span><span style="font-size: 14px; line-height: 25px; font-family: Verdana, Arial, Helvetica, sans-serif;"><div><a href="http://www.libuchao.com/2012/05/14/prototypes-in-javascript/">http://www.libuchao.com/2012/05/14/prototypes-in-javascript/</a>&nbsp;(JavaScript 的原型对象 Prototype)</div><div><a href="http://rockyuse.iteye.com/blog/1426510">http://rockyuse.iteye.com/blog/1426510</a>&nbsp;(理解js中的原型链，prototype与__proto__的关系)</div></span></div><br /><br /><br /></div><img src ="http://www.blogjava.net/heavensay/aggbug/405440.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/heavensay/" target="_blank">heavensay</a> 2013-10-20 23:47 <a href="http://www.blogjava.net/heavensay/archive/2013/10/20/405440.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>