Skip to content

Commit bef7ad1

Browse files
committed
Built Programing-In-Javascript from commit 8aa9cd5 on branch master
1 parent dae8176 commit bef7ad1

File tree

4 files changed

+90
-50
lines changed

4 files changed

+90
-50
lines changed

Browser_Scripting/DOM_Scripting/EventAPI.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ <h3 id="eventtarget-">EventTarget和节点元素</h3>
4343
<p>在应用Javascript进行DOM编程时时,事件的产生源头很多,同时,事件的订阅也存在多种形式。从事件源头看,拥有能够接受事件DOM事件的对象,都实现了<code>EventTarget</code>接口。下面这三个方法,大家应该都不陌生。</p>
4444
<pre><code>EventTarget.addEventListener ()
4545
EventTarget.removeEventListener ()
46-
EventTarget.dispatchEvent ()</code></pre>
47-
<p>DOM内的文档元素,大多都有如下的继承状态:</p>
46+
EventTarget.dispatchEvent ()
47+
</code></pre><p>DOM内的文档元素,大多都有如下的继承状态:</p>
4848
<pre><code>EventTarget -&gt; Node -&gt; |-&gt; Element -&gt; HTMLElement -&gt; ...
4949
|-&gt; Document
50-
|-&gt; ...</code></pre>
51-
<p>如上所述,大多素我们获取的节点,都是有相关的事件方法的。但由于历史原因,有大量DOM0时期(即没有标准化)的代码,可以使用以下两种办法注册事件监听:</p>
50+
|-&gt; ...
51+
</code></pre><p>如上所述,大多素我们获取的节点,都是有相关的事件方法的。但由于历史原因,有大量DOM0时期(即没有标准化)的代码,可以使用以下两种办法注册事件监听:</p>
5252
<ul>
5353
<li><p>通过HTML属性</p>
54-
<pre><code> &lt;button onclick=&quot;alert(&#39;Hello world!&#39;)&quot;&gt;</code></pre>
55-
</li>
54+
<pre><code> &lt;button onclick=&quot;alert(&#39;Hello world!&#39;)&quot;&gt;
55+
</code></pre></li>
5656
<li><p>通过DOM元素属性</p>
57-
<pre><code> myButton.onclick = function(event){alert(&#39;Hello world&#39;);};</code></pre>
58-
</li>
57+
<pre><code> myButton.onclick = function(event){alert(&#39;Hello world&#39;);};
58+
</code></pre></li>
5959
</ul>
6060
<h3 id="-">事件派发</h3>
6161
<p>事件可以通过调用<code>EventTarget.dispatchEvent()</code>进行派发,浏览器自己也需要遵循该方法的行为自动派发相应事件。整个事件派发的流程如下:</p>
@@ -123,8 +123,8 @@ <h2 id="-">参考文档</h2>
123123
</div>
124124
<div class="right">
125125
<ul class="inline-list">
126-
<li>Rev <a href="https://github.com/RobinQu/Programing-In-Javascript/tree/5870e0e/chapters/Browser_Scripting/DOM_Scripting/EventAPI.md">5870e0e</a></li>
127-
<li>Thu Mar 27 2014 17:42:10 GMT+0800 (CST)</li>
126+
<li>Rev <a href="https://github.com/RobinQu/Programing-In-Javascript/tree/65f38de/chapters/Browser_Scripting/DOM_Scripting/EventAPI.md">65f38de</a></li>
127+
<li>Thu Mar 27 2014 19:21:58 GMT+0800 (CST)</li>
128128
</ul>
129129
</div>
130130
</footer>

Browser_Scripting/Document_Loading/ScriptExecution.html

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@ <h2 id="-">执行入口</h2>
4545
</ul>
4646
<h3 id="script-">script标签</h3>
4747
<p>最基本,最常用的脚本引入方式。例如:</p>
48-
<pre><code>&lt;script src=&quot;http://code.jquery.com/jquery-1.11.0.min.js&quot;&gt;&lt;/script&gt;</code></pre>
49-
<p>尽管在HTML4和XHTML里面,要求开发者使用<code>type</code>属性来制定脚本的类型。但是主流浏览器都默认认为脚本类型是<code>text/javascript</code></p>
50-
<p>在HTML5的规范内<a href="http://www.w3.org/html/wg/drafts/html/master/scripting-1.html#the-script-element">^1</a><code>script</code>标签的type属性是完全可选的。</p>
48+
<pre><code>&lt;script src=&quot;http://code.jquery.com/jquery-1.11.0.min.js&quot;&gt;&lt;/script&gt;
49+
</code></pre><p>尽管在HTML4和XHTML里面,要求开发者使用<code>type</code>属性来制定脚本的类型。但是主流浏览器都默认认为脚本类型是<code>text/javascript</code></p>
50+
<p>在HTML5的规范内<sup id="fnref1"><a href="#fn1">1</a></sup><code>script</code>标签的type属性是完全可选的。</p>
5151
<h3 id="eval-">eval函数</h3>
5252
<ul>
5353
<li><code>eval</code> is evil</li>
5454
<li><code>eval</code>有访问本地scope的权利</li>
5555
</ul>
5656
<pre><code>var a = 1;
5757
eval(&quot;a=2&quot;);
58-
a === 2; // ==&gt; true</code></pre>
59-
<h3 id="function-">Function构造函数</h3>
58+
a === 2; // ==&gt; true
59+
</code></pre><h3 id="function-">Function构造函数</h3>
6060
<ul>
61-
<li>function是“first-class citizen”<a href="https://developer.mozilla.org/en-US/docs/functional-javascript/First-class_citizen">^2</a>;自然有相应的构造函数</li>
61+
<li>function是“first-class citizen”<sup id="fnref2"><a href="#fn2">2</a></sup>;自然有相应的构造函数</li>
6262
<li><code>new Function(arg1, arg2, ..., fnStr)</code></li>
63-
<li><code>Function</code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">^3</a>构造函数本质是创建一个函数对象;其创建的函数执行也并不能访问其所在创建环境的闭包,只能访问本地作用域(local scope)和全局作用域(global scope)</li>
63+
<li><code>Function</code><sup id="fnref3"><a href="#fn3">3</a></sup>构造函数本质是创建一个函数对象;其创建的函数执行也并不能访问其所在创建环境的闭包,只能访问本地作用域(local scope)和全局作用域(global scope)</li>
6464
<li><code>Function()</code><code>new Function()</code>效果一样</li>
6565
</ul>
6666
<pre><code>(function() {
@@ -69,16 +69,31 @@ <h3 id="function-">Function构造函数</h3>
6969
func();
7070
a === 2; // ==&gt; false
7171
}());
72-
a === 2; // ==&gt; true</code></pre>
73-
<h3 id="settimeout-setinterval">setTimeout和setInterval</h3>
74-
<pre><code>setTimeout(&quot;alert(&#39;haha&#39;)&quot;, 0);</code></pre>
75-
<p>这个和eval有异曲同工之妙,对作用域的访问也是类似的。</p>
76-
<p>另外要说名,以上几点,除了script标签的方法之外,其他方法都在<code>strict</code>模式<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode">^4</a>下不可用。</p>
72+
a === 2; // ==&gt; true
73+
</code></pre><h3 id="settimeout-setinterval">setTimeout和setInterval</h3>
74+
<pre><code>setTimeout(&quot;alert(&#39;haha&#39;)&quot;, 0);
75+
</code></pre><p>这个和eval有异曲同工之妙,对作用域的访问也是类似的。</p>
76+
<p>另外要说名,以上几点,除了script标签的方法之外,其他方法都在<code>strict</code>模式<sup id="fnref4"><a href="#fn4">4</a></sup>下不可用。</p>
7777
<h3 id="html-">HTML內联事件回调</h3>
78-
<pre><code>&lt;a href=&#39;#hello&#39; onclick=&quot;alert(this.href)&quot;&gt;Say hello&lt;/a&gt;</code></pre>
79-
<p>这样如同在click事件的<code>Target Phase</code>运行了一个回调。<code>this</code>指向目标元素本身。</p>
78+
<pre><code>&lt;a href=&#39;#hello&#39; onclick=&quot;alert(this.href)&quot;&gt;Say hello&lt;/a&gt;
79+
</code></pre><p>这样如同在click事件的<code>Target Phase</code>运行了一个回调。<code>this</code>指向目标元素本身。</p>
8080
<h3 id="-hack">其他Hack</h3>
81-
<p>利用MessageChannel等新特性可以触发一些函数的执行<a href="https://github.com/kriskowal/asap/blob/master/asap.js">^5</a>。也许Javascript的其他的角落也有不少其他执行脚本的入口吧。</p>
81+
<p>利用MessageChannel等新特性可以触发一些函数的执行<sup id="fnref5"><a href="#fn5">5</a></sup>。也许Javascript的其他的角落也有不少其他执行脚本的入口吧。</p>
82+
<hr>
83+
<div class="footnotes">
84+
<ol>
85+
<li id="fn1"><p><a href="http://www.w3.org/html/wg/drafts/html/master/scripting-1.html#the-script-element">http://www.w3.org/html/wg/drafts/html/master/scripting-1.html#the-script-element</a></p>
86+
<a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1 in the text."></a></li>
87+
<li id="fn2"><p><a href="https://developer.mozilla.org/en-US/docs/functional-javascript/First-class_citizen">https://developer.mozilla.org/en-US/docs/functional-javascript/First-class_citizen</a></p>
88+
<a href="#fnref2" class="footnoteBackLink" title="Jump back to footnote 2 in the text."></a></li>
89+
<li id="fn3"><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function</a></p>
90+
<a href="#fnref3" class="footnoteBackLink" title="Jump back to footnote 3 in the text."></a></li>
91+
<li id="fn4"><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/Strict_mode</a></p>
92+
<a href="#fnref4" class="footnoteBackLink" title="Jump back to footnote 4 in the text."></a></li>
93+
<li id="fn5"><p><a href="https://github.com/kriskowal/asap/blob/master/asap.js">https://github.com/kriskowal/asap/blob/master/asap.js</a></p>
94+
<a href="#fnref5" class="footnoteBackLink" title="Jump back to footnote 5 in the text."></a></li>
95+
</ol>
96+
</div>
8297

8398
</div>
8499
<footer class="misc clearfix">
@@ -92,8 +107,8 @@ <h3 id="-hack">其他Hack</h3>
92107
</div>
93108
<div class="right">
94109
<ul class="inline-list">
95-
<li>Rev <a href="https://github.com/RobinQu/Programing-In-Javascript/tree/5870e0e/chapters/Browser_Scripting/Document_Loading/ScriptExecution.md">5870e0e</a></li>
96-
<li>Thu Mar 27 2014 17:42:10 GMT+0800 (CST)</li>
110+
<li>Rev <a href="https://github.com/RobinQu/Programing-In-Javascript/tree/65f38de/chapters/Browser_Scripting/Document_Loading/ScriptExecution.md">65f38de</a></li>
111+
<li>Thu Mar 27 2014 19:21:58 GMT+0800 (CST)</li>
97112
</ul>
98113
</div>
99114
</footer>

0 commit comments

Comments
 (0)