<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Da&#39;sBlog</title>
  
  <link href="/atom.xml" rel="self"/>
  
  <link href="http://sunhao.win/"/>
  <updated>2018-03-06T08:06:40.980Z</updated>
  <id>http://sunhao.win/</id>
  
  <author>
    <name>Sun Hao</name>
    
  </author>
  
  <generator uri="http://hexo.io/">Hexo</generator>
  
  <entry>
    <title>js-arrow</title>
    <link href="http://sunhao.win/articles/js-arrow.html"/>
    <id>http://sunhao.win/articles/js-arrow.html</id>
    <published>2018-03-06T08:06:25.000Z</published>
    <updated>2018-03-06T08:06:40.980Z</updated>
    
    <content type="html"><![CDATA[<p>  var a = {<br>            b: function() {<br>                console.log(this)<br>            },<br>            c: () =&gt; console.log(this),<br>            d() {<br>                console.log(this)<br>            },<br>            e() {<br>                return new Promise(<br>                    () =&gt; console.log(this)<br>                )<br>            },<br>            f: function() {<br>                return new Promise(<br>                    () =&gt; console.log(this)<br>                )<br>            },<br>            g: function() {<br>                return new Promise(<br>                    () =&gt; console.log(this.axios)<br>                )<br>            },</p>
<pre><code>        i() {
            return () =&gt; (
                console.log(this.axios)

            )

        },
        h() {
            return () =&gt; ({
                i() {
                    console.log(this.axios)
                }
            })
        },
        o() {
            return () =&gt; {
                return () =&gt; {
                    console.log(this.axios)
                }
            }
        },
        p() {
            return () =&gt; {
                return () =&gt; ({
                    i() {
                        console.log(this.axios)
                    }
                })
            }
        },
        u: () =&gt; ({
            i() {
                console.log(this.axios)
            }
        }),
        y: () =&gt; ({
            i: () =&gt; (console.log(this))
        }),
    }
    // es6 浏览器隐式调用 strict mode。u内部所在作用于是window但箭头函数内的i的调用caller和argument受到限制，所以返回underfined
a.axios = 1;
axios = &quot;&quot;;
</code></pre><a id="more"></a>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;  var a = {&lt;br&gt;            b: function() {&lt;br&gt;                console.log(this)&lt;br&gt;            },&lt;br&gt;            c: () =&amp;gt; console.log(this),&lt;br&gt;            d() {&lt;br&gt;                console.log(this)&lt;br&gt;            },&lt;br&gt;            e() {&lt;br&gt;                return new Promise(&lt;br&gt;                    () =&amp;gt; console.log(this)&lt;br&gt;                )&lt;br&gt;            },&lt;br&gt;            f: function() {&lt;br&gt;                return new Promise(&lt;br&gt;                    () =&amp;gt; console.log(this)&lt;br&gt;                )&lt;br&gt;            },&lt;br&gt;            g: function() {&lt;br&gt;                return new Promise(&lt;br&gt;                    () =&amp;gt; console.log(this.axios)&lt;br&gt;                )&lt;br&gt;            },&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;        i() {
            return () =&amp;gt; (
                console.log(this.axios)

            )

        },
        h() {
            return () =&amp;gt; ({
                i() {
                    console.log(this.axios)
                }
            })
        },
        o() {
            return () =&amp;gt; {
                return () =&amp;gt; {
                    console.log(this.axios)
                }
            }
        },
        p() {
            return () =&amp;gt; {
                return () =&amp;gt; ({
                    i() {
                        console.log(this.axios)
                    }
                })
            }
        },
        u: () =&amp;gt; ({
            i() {
                console.log(this.axios)
            }
        }),
        y: () =&amp;gt; ({
            i: () =&amp;gt; (console.log(this))
        }),
    }
    // es6 浏览器隐式调用 strict mode。u内部所在作用于是window但箭头函数内的i的调用caller和argument受到限制，所以返回underfined
a.axios = 1;
axios = &amp;quot;&amp;quot;;
&lt;/code&gt;&lt;/pre&gt;
    
    </summary>
    
    
  </entry>
  
  <entry>
    <title>apache卸载添加模块</title>
    <link href="http://sunhao.win/articles/apache%E5%8D%B8%E8%BD%BD%E6%B7%BB%E5%8A%A0%E6%A8%A1%E5%9D%97.html"/>
    <id>http://sunhao.win/articles/apache卸载添加模块.html</id>
    <published>2018-01-24T08:42:35.000Z</published>
    <updated>2018-01-25T05:34:13.567Z</updated>
    
    <content type="html"><![CDATA[<p>1.安装apache2<br>安装命令：sudo apt-get install apache2<br>启动/停止/重启apache2: service apache2 start/stop/restart</p>
<ol>
<li>卸载apache2<br>之前卸载重新安装后找不到apache2.conf配置文件，测试使用一下方式卸载后可用。<br>(1)  $ sudo apt-get –purge remove apache2<pre><code>$ sudo apt-get --purge remove apache2.2-common
$ sudo apt-get autoremove
</code></pre></li>
</ol>
<p>(2) （关键一步）找到没有删除掉的配置文件，一并删除<br>       $ sudo find  /etc -name “<em>apache</em>“ -exec  rm -rf {} \;<br>       $ sudo rm -rf /var/www</p>
<p>然而,在安装成功准备运行的时候,却出现了问题如下所示:<br>[Fri Oct 14 20:27:03.977120 2016] [core:warn] [pid 4445] AH00111: Config variable ${APACHE_LOCK_DIR} is not defined</p>
<p>[Fri Oct 14 20:27:03.977236 2016] [core:warn] [pid 4445] AH00111: Config variable ${APACHE_PID_FILE} is not defined</p>
<p>[Fri Oct 14 20:27:03.977267 2016] [core:warn] [pid 4445] AH00111: Config variable ${APACHE_RUN_USER} is not defined</p>
<p>[Fri Oct 14 20:27:03.977273 2016] [core:warn] [pid 4445] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined</p>
<p>[Fri Oct 14 20:27:03.977283 2016] [core:warn] [pid 4445] AH00111: Config variable ${APACHE_LOG_DIR} is not defined</p>
<p>[Fri Oct 14 20:27:03.979139 2016] [core:warn] [pid 4445:tid 140654039287680] AH00111: Config variable ${APACHE_LOG_DIR} is not defined</p>
<p>[Fri Oct 14 20:27:03.981408 2016] [core:warn] [pid 4445:tid 140654039287680] AH00111: Config variable ${APACHE_LOG_DIR} is not defined</p>
<p>[Fri Oct 14 20:27:03.981422 2016] [core:warn] [pid 4445:tid 140654039287680] AH00111: Config variable ${APACHE_LOG_DIR} is not defined</p>
<p>AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:</p>
<p>如果不能正常启动。<br>这个多半是以前卸载的时候没有卸载干净 重新完整卸载一遍就好。</p>
<p>在apache1时候静态php模块直接编译进核心mod模块<br>在apache2不再内置。<br>就意味着不用 Apache 内置的 mod_php，也就是要在 Apache 之外处理 php 程序的解释运行问题。看起来是多引入了一个额外的程序 PHP-FPM，既占 CPU 又占内存。但是这样一来，因为 Apache 可以专心处理除 php 之外的静态网页及元素，反而 httpd 进程本身占用的 CPU 和内存可以显著降低，从而从整体上降低资源消耗。</p>
<p>安装5.6  7.1的php后<br>默认源自动添加了apache2的模块。如果没有需要手动安装添加<br>例如<br>sudo apt-get install libapache2-mod-php5.6</p>
<p>apache2通过模块连接到php。</p>
<p>从PHP 5.6 =&gt; PHP 7.1</p>
<p>默认PHP 5.6在您的系统上设置，您需要切换到PHP 7.1。</p>
<p>Apache： –</p>
<p>$ sudo a2dismod php5.6<br>a2dismod关闭5.6模块<br>$ sudo a2enmod php7.1<br>a2enmod开启7.1的模块   </p>
<p>$ sudo service apache2 restart<br>命令行：-</p>
<p>$ update-alternatives –set php /usr/bin/php7.1<br>同时用update-alternatives修改  为7.1的软连接。</p>
<p>从PHP 7.1 =&gt; PHP 5.6</p>
<p>默认PHP 7.1在您的系统上设置，您需要切换到PHP 5.6。</p>
<p>Apache： –</p>
<p>$ sudo a2dismod php7.1<br>$ sudo a2enmod php5.6<br>$ sudo service apache2 restart<br>命令行：-</p>
<p>$ sudo update-alternatives –set php /usr/bin/php5.6</p>
<p>如果在a2enmodphp5.6出现 “Module php5.6 does not exist”<br>多半是apache内 没有加载上模块<br>我们创建两个文件就好了</p>
<p>文件1<br>复制下面内容创建 php5.6.conf 在 /etc/apache2/mods-available/ :</p>
<ifmodule mod_php5.c=""><br>  AddType application/x-httpd-php .php .phtml .php5<br>  AddType application/x-httpd-php-source .phps<br></ifmodule>

<p>文件2</p>
<p>复制下面内容创建php.load 同样在 /etc/apache2/mods-available/  </p>
<p>LoadModule php5_module /usr/lib/apache2/modules/libphp5.so</p>
<p>保存好后退出输入<br>a2enmod php &amp;&amp; /etc/init.d/apache2 restart<br><a id="more"></a></p>
<p>Ubuntu – 安装和部署php5.6 nginx php5.6-fpm</p>
<p>1.首先输入用户名和密码进行登录</p>
<p>2.升级更新软件包</p>
<p>sudo apt-get update</p>
<p>sudo apt-get upgrade</p>
<p>判断都填y</p>
<p>3.安装nginx</p>
<p>sudo apt-get install nginx</p>
<p>在浏览器输入你的ip地址测试是否安装成功</p>
<ol>
<li>PHP<br>apt-get -y update<br>add-apt-repository ppa:ondrej/php<br>apt-get -y update<br>apt-get -y install php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd<br>php5.6-xml php5.6-fpm</li>
</ol>
<p>4.安装数据库</p>
<p>sudo apt-get install mysql-server php5-mysql</p>
<p>过程中要输入两次数据库的密码</p>
<p>输入mysql -u root -p 测试数据库安装是否成功</p>
<p>quit 可以退出</p>
<p>5.安装php-fpm</p>
<p>sudo apt-get install php5-fpm</p>
<p>6.配置php-fpm</p>
<p>sudo vi /etc/php5/fpm/php.ini</p>
<p>将;cgi.fix_pathinfo=1改成cgi.fix_pathinfo=0(还要去掉分号)  位置在全屏状态下的40%的第一行，看右下角</p>
<p>修改保存内容的方法自己查看vi 的操作</p>
<p>7.重启php-fpm</p>
<p>sudo service php5-fpm restart</p>
<p>8.解决nginx打开php文件总是显示下载框的问题</p>
<p>sudo vi /etc/nginx/sites-available/default</p>
<p>去掉注释保存</p>
<p>9.重启nginx</p>
<p>sudo service nginx restart</p>
<p>10.测试nginx是否解析php</p>
<p>cd /usr/share/nginx/html</p>
<p>sudo vi index.php</p>
<p>在index.php中输入</p>
<p>&lt;?php phpinfo();  ?&gt;</p>
<p>11.修改权限</p>
<p>1)首先进入服务器根目录 cd usr/share/nginx</p>
<p>2)再使用chmod      sudo chmod 777 html/</p>
]]></content>
    
    <summary type="html">
    
      &lt;p&gt;1.安装apache2&lt;br&gt;安装命令：sudo apt-get install apache2&lt;br&gt;启动/停止/重启apache2: service apache2 start/stop/restart&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;卸载apache2&lt;br&gt;之前卸载重新安装后找不到apache2.conf配置文件，测试使用一下方式卸载后可用。&lt;br&gt;(1)  $ sudo apt-get –purge remove apache2&lt;pre&gt;&lt;code&gt;$ sudo apt-get --purge remove apache2.2-common
$ sudo apt-get autoremove
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;(2) （关键一步）找到没有删除掉的配置文件，一并删除&lt;br&gt;       $ sudo find  /etc -name “&lt;em&gt;apache&lt;/em&gt;“ -exec  rm -rf {} \;&lt;br&gt;       $ sudo rm -rf /var/www&lt;/p&gt;
&lt;p&gt;然而,在安装成功准备运行的时候,却出现了问题如下所示:&lt;br&gt;[Fri Oct 14 20:27:03.977120 2016] [core:warn] [pid 4445] AH00111: Config variable ${APACHE_LOCK_DIR} is not defined&lt;/p&gt;
&lt;p&gt;[Fri Oct 14 20:27:03.977236 2016] [core:warn] [pid 4445] AH00111: Config variable ${APACHE_PID_FILE} is not defined&lt;/p&gt;
&lt;p&gt;[Fri Oct 14 20:27:03.977267 2016] [core:warn] [pid 4445] AH00111: Config variable ${APACHE_RUN_USER} is not defined&lt;/p&gt;
&lt;p&gt;[Fri Oct 14 20:27:03.977273 2016] [core:warn] [pid 4445] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined&lt;/p&gt;
&lt;p&gt;[Fri Oct 14 20:27:03.977283 2016] [core:warn] [pid 4445] AH00111: Config variable ${APACHE_LOG_DIR} is not defined&lt;/p&gt;
&lt;p&gt;[Fri Oct 14 20:27:03.979139 2016] [core:warn] [pid 4445:tid 140654039287680] AH00111: Config variable ${APACHE_LOG_DIR} is not defined&lt;/p&gt;
&lt;p&gt;[Fri Oct 14 20:27:03.981408 2016] [core:warn] [pid 4445:tid 140654039287680] AH00111: Config variable ${APACHE_LOG_DIR} is not defined&lt;/p&gt;
&lt;p&gt;[Fri Oct 14 20:27:03.981422 2016] [core:warn] [pid 4445:tid 140654039287680] AH00111: Config variable ${APACHE_LOG_DIR} is not defined&lt;/p&gt;
&lt;p&gt;AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:&lt;/p&gt;
&lt;p&gt;如果不能正常启动。&lt;br&gt;这个多半是以前卸载的时候没有卸载干净 重新完整卸载一遍就好。&lt;/p&gt;
&lt;p&gt;在apache1时候静态php模块直接编译进核心mod模块&lt;br&gt;在apache2不再内置。&lt;br&gt;就意味着不用 Apache 内置的 mod_php，也就是要在 Apache 之外处理 php 程序的解释运行问题。看起来是多引入了一个额外的程序 PHP-FPM，既占 CPU 又占内存。但是这样一来，因为 Apache 可以专心处理除 php 之外的静态网页及元素，反而 httpd 进程本身占用的 CPU 和内存可以显著降低，从而从整体上降低资源消耗。&lt;/p&gt;
&lt;p&gt;安装5.6  7.1的php后&lt;br&gt;默认源自动添加了apache2的模块。如果没有需要手动安装添加&lt;br&gt;例如&lt;br&gt;sudo apt-get install libapache2-mod-php5.6&lt;/p&gt;
&lt;p&gt;apache2通过模块连接到php。&lt;/p&gt;
&lt;p&gt;从PHP 5.6 =&amp;gt; PHP 7.1&lt;/p&gt;
&lt;p&gt;默认PHP 5.6在您的系统上设置，您需要切换到PHP 7.1。&lt;/p&gt;
&lt;p&gt;Apache： –&lt;/p&gt;
&lt;p&gt;$ sudo a2dismod php5.6&lt;br&gt;a2dismod关闭5.6模块&lt;br&gt;$ sudo a2enmod php7.1&lt;br&gt;a2enmod开启7.1的模块   &lt;/p&gt;
&lt;p&gt;$ sudo service apache2 restart&lt;br&gt;命令行：-&lt;/p&gt;
&lt;p&gt;$ update-alternatives –set php /usr/bin/php7.1&lt;br&gt;同时用update-alternatives修改  为7.1的软连接。&lt;/p&gt;
&lt;p&gt;从PHP 7.1 =&amp;gt; PHP 5.6&lt;/p&gt;
&lt;p&gt;默认PHP 7.1在您的系统上设置，您需要切换到PHP 5.6。&lt;/p&gt;
&lt;p&gt;Apache： –&lt;/p&gt;
&lt;p&gt;$ sudo a2dismod php7.1&lt;br&gt;$ sudo a2enmod php5.6&lt;br&gt;$ sudo service apache2 restart&lt;br&gt;命令行：-&lt;/p&gt;
&lt;p&gt;$ sudo update-alternatives –set php /usr/bin/php5.6&lt;/p&gt;
&lt;p&gt;如果在a2enmodphp5.6出现 “Module php5.6 does not exist”&lt;br&gt;多半是apache内 没有加载上模块&lt;br&gt;我们创建两个文件就好了&lt;/p&gt;
&lt;p&gt;文件1&lt;br&gt;复制下面内容创建 php5.6.conf 在 /etc/apache2/mods-available/ :&lt;/p&gt;
&lt;ifmodule mod_php5.c=&quot;&quot;&gt;&lt;br&gt;  AddType application/x-httpd-php .php .phtml .php5&lt;br&gt;  AddType application/x-httpd-php-source .phps&lt;br&gt;&lt;/ifmodule&gt;

&lt;p&gt;文件2&lt;/p&gt;
&lt;p&gt;复制下面内容创建php.load 同样在 /etc/apache2/mods-available/  &lt;/p&gt;
&lt;p&gt;LoadModule php5_module /usr/lib/apache2/modules/libphp5.so&lt;/p&gt;
&lt;p&gt;保存好后退出输入&lt;br&gt;a2enmod php &amp;amp;&amp;amp; /etc/init.d/apache2 restart&lt;br&gt;
    
    </summary>
    
    
  </entry>
  
  <entry>
    <title>rpx教程</title>
    <link href="http://sunhao.win/articles/rpx%E6%95%99%E7%A8%8B.html"/>
    <id>http://sunhao.win/articles/rpx教程.html</id>
    <published>2018-01-16T06:14:19.000Z</published>
    <updated>2018-01-16T07:17:54.110Z</updated>
    
    <content type="html"><![CDATA[<p>rpx默认把屏幕实际宽度分成750份。</p>
<p>那么在750物理宽度的iphone6上，实际宽度是750,1rpx =375/750= 0.5px</p>
<p>那么在640物理宽度的iphone5，实际宽度是640，物理宽度是320，  1rpx= 320/750 =  0.426666666666666px</p>
<p>所以如果你的设计稿假如是640的   就要用iphone5的像素计算，就要先转成实际像素，   然后把他750等分。 </p>
<p>工作中我们的数值都是像素</p>
<p>所以要把设计稿的像素转成rpx</p>
<p>也就是说  实际像素320</p>
<p>页面有750份。</p>
<p>那么我们得到1px  = 750/320像素 =   2.34375rpx</p>
<p>但我们的设计稿是640</p>
<p>那么我们的换算应该是1px  = 750/640像素   =  2.34375rpx/2 = 1.171875rpx;</p>
<p>即在640下，60px的方块。这么计算</p>
<p>60*1.171875rpx; = 70.3125rpx</p>
<p>看似复杂换个角度想，无论任何屏幕都是750份，</p>
<p>那么你也可以估算出1等分大概是多少，计算出实际大小</p>
<p>这个与rem是类似的，</p>
<p>假如rem在375下，分成750份。  那么1rem = 1rpx =375/750= 0.5px<br>那么750下也是750份。<br>640下也是750份。</p>
<p>至于原理，<br>要始终明白一点<br>有个比值是不变的就是 分割数750，即基数。<br>即<br>我把面包分成5份，那么无论面包变大变小，那个分成5份占总体积的大小是不变。</p>
<p>而在这里，我们的的面包是320px大小，我分成了750份，1份大小即1rpx = 320/750。 那么当面包变成了640px,里面还是750份 一份大小 1rpx = 640/750。</p>
<p>好了<br>为了方便计算。<br>因为实际有些人喜欢多吃面包，所以不是每人都给一份，因为我有时候给某人多一点。而且我不可能都切完。我就用尺子量下我的面包宽度。要分一个100px的面包<br>那么640的面包   1px的面包大概是750/640 = 1.17rpx  如果我要给某人100px的面包，那么值就是1.17rpx *100 - 117rpx 也就是只需要给117份。</p>
<p>那么无论变大变小 无都不用管  他都是117份</p>
<p>但是如果是厘米的话我就估算不出来了。因为大小变了。</p>
<a id="more"></a>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;rpx默认把屏幕实际宽度分成750份。&lt;/p&gt;
&lt;p&gt;那么在750物理宽度的iphone6上，实际宽度是750,1rpx =375/750= 0.5px&lt;/p&gt;
&lt;p&gt;那么在640物理宽度的iphone5，实际宽度是640，物理宽度是320，  1rpx= 320/750 =  0.426666666666666px&lt;/p&gt;
&lt;p&gt;所以如果你的设计稿假如是640的   就要用iphone5的像素计算，就要先转成实际像素，   然后把他750等分。 &lt;/p&gt;
&lt;p&gt;工作中我们的数值都是像素&lt;/p&gt;
&lt;p&gt;所以要把设计稿的像素转成rpx&lt;/p&gt;
&lt;p&gt;也就是说  实际像素320&lt;/p&gt;
&lt;p&gt;页面有750份。&lt;/p&gt;
&lt;p&gt;那么我们得到1px  = 750/320像素 =   2.34375rpx&lt;/p&gt;
&lt;p&gt;但我们的设计稿是640&lt;/p&gt;
&lt;p&gt;那么我们的换算应该是1px  = 750/640像素   =  2.34375rpx/2 = 1.171875rpx;&lt;/p&gt;
&lt;p&gt;即在640下，60px的方块。这么计算&lt;/p&gt;
&lt;p&gt;60*1.171875rpx; = 70.3125rpx&lt;/p&gt;
&lt;p&gt;看似复杂换个角度想，无论任何屏幕都是750份，&lt;/p&gt;
&lt;p&gt;那么你也可以估算出1等分大概是多少，计算出实际大小&lt;/p&gt;
&lt;p&gt;这个与rem是类似的，&lt;/p&gt;
&lt;p&gt;假如rem在375下，分成750份。  那么1rem = 1rpx =375/750= 0.5px&lt;br&gt;那么750下也是750份。&lt;br&gt;640下也是750份。&lt;/p&gt;
&lt;p&gt;至于原理，&lt;br&gt;要始终明白一点&lt;br&gt;有个比值是不变的就是 分割数750，即基数。&lt;br&gt;即&lt;br&gt;我把面包分成5份，那么无论面包变大变小，那个分成5份占总体积的大小是不变。&lt;/p&gt;
&lt;p&gt;而在这里，我们的的面包是320px大小，我分成了750份，1份大小即1rpx = 320/750。 那么当面包变成了640px,里面还是750份 一份大小 1rpx = 640/750。&lt;/p&gt;
&lt;p&gt;好了&lt;br&gt;为了方便计算。&lt;br&gt;因为实际有些人喜欢多吃面包，所以不是每人都给一份，因为我有时候给某人多一点。而且我不可能都切完。我就用尺子量下我的面包宽度。要分一个100px的面包&lt;br&gt;那么640的面包   1px的面包大概是750/640 = 1.17rpx  如果我要给某人100px的面包，那么值就是1.17rpx *100 - 117rpx 也就是只需要给117份。&lt;/p&gt;
&lt;p&gt;那么无论变大变小 无都不用管  他都是117份&lt;/p&gt;
&lt;p&gt;但是如果是厘米的话我就估算不出来了。因为大小变了。&lt;/p&gt;
    
    </summary>
    
      <category term="微信小程序" scheme="http://sunhao.win/categories/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/"/>
    
    
      <category term="微信" scheme="http://sunhao.win/tags/%E5%BE%AE%E4%BF%A1/"/>
    
      <category term="rpx" scheme="http://sunhao.win/tags/rpx/"/>
    
  </entry>
  
  <entry>
    <title>learn-thinkcmf</title>
    <link href="http://sunhao.win/articles/learn-thinkcmf.html"/>
    <id>http://sunhao.win/articles/learn-thinkcmf.html</id>
    <published>2017-12-20T08:26:40.000Z</published>
    <updated>2017-12-26T06:14:12.894Z</updated>
    
    <content type="html"><![CDATA[<ol>
<li><p>在写样式的时候不要在外部设置高度</p>
</li>
<li><p>lock上传后 一定要加上</p>
</li>
</ol>
<ol>
<li>获取请求的category的值，如果没有设置为0，并且转成整形。$categoryId = $this-&gt;request-&gt;param(‘category’, 0, ‘intval’);</li>
</ol>
<ol>
<li>表达式<br>   $join = [<pre><code>    [&apos;__USER__ u&apos;, &apos;a.user_id = u.id&apos;]
];
</code></pre>user表设置名称为u，判断条件是否相等<a id="more"></a></li>
</ol>
]]></content>
    
    <summary type="html">
    
      &lt;ol&gt;
&lt;li&gt;&lt;p&gt;在写样式的时候不要在外部设置高度&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;lock上传后 一定要加上&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;ol&gt;
&lt;li&gt;获取请求的category的值，如果没有设置为0，并且转成整形。$categoryId = $this-&amp;gt;request-&amp;gt;param(‘category’, 0, ‘intval’);&lt;/li&gt;
&lt;/ol&gt;
&lt;ol&gt;
&lt;li&gt;表达式&lt;br&gt;   $join = [&lt;pre&gt;&lt;code&gt;    [&amp;apos;__USER__ u&amp;apos;, &amp;apos;a.user_id = u.id&amp;apos;]
];
&lt;/code&gt;&lt;/pre&gt;user表设置名称为u，判断条件是否相等
    
    </summary>
    
    
  </entry>
  
  <entry>
    <title>git-pull错误refusing to merge unrelated histories</title>
    <link href="http://sunhao.win/articles/histories.html"/>
    <id>http://sunhao.win/articles/histories.html</id>
    <published>2017-11-06T07:15:52.000Z</published>
    <updated>2017-11-06T08:58:18.486Z</updated>
    
    <content type="html"><![CDATA[<p>在服务器创建好后  应该先拉到本地 再推。</p>
<p>提前推是会报错的。</p>
<p>如果本地已经创建项目  需要合并下。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line">H:\zcll&gt;git remote add zcll https://git.coding.net/da_/zcll.git</div><div class="line"></div><div class="line">H:\zcll&gt;git push -u zcll master</div><div class="line">To https://git.coding.net/da_/zcll.git</div><div class="line"> ! [rejected]        master -&gt; master (non-fast-forward)</div><div class="line">error: failed to push some refs to &apos;https://git.coding.net/da_/zcll.git&apos;</div><div class="line">hint: Updates were rejected because the tip of your current branch is behind</div><div class="line">hint: its remote counterpart. Integrate the remote changes (e.g.</div><div class="line">hint: &apos;git pull ...&apos;) before pushing again.</div><div class="line">hint: See the &apos;Note about fast-forwards&apos; in &apos;git push --help&apos; for details.</div><div class="line"></div><div class="line">H:\zcll&gt;git pull zcll master</div><div class="line">From https://git.coding.net/da_/zcll</div><div class="line"> * branch            master     -&gt; FETCH_HEAD</div><div class="line">fatal: refusing to merge unrelated histories</div><div class="line"></div><div class="line"></div><div class="line">H:\zcll&gt;git pull zcll master  --allow-unrelated-histories</div><div class="line">From https://git.coding.net/da_/zcll</div><div class="line"> * branch            master     -&gt; FETCH_HEAD</div><div class="line">Merge made by the &apos;recursive&apos; strategy.</div><div class="line"> README.md | 1 +</div><div class="line"> 1 file changed, 1 insertion(+)</div><div class="line"> create mode 100644 README.md</div><div class="line"></div><div class="line"></div><div class="line">H:\zcll&gt;git push -u zcll master</div><div class="line">Counting objects: 148, done.</div><div class="line">Delta compression using up to 4 threads.</div><div class="line">Compressing objects: 100% (140/140), done.</div><div class="line">Writing objects: 100% (148/148), 3.35 MiB | 673.00 KiB/s, done.</div><div class="line">Total 148 (delta 19), reused 0 (delta 0)</div><div class="line">remote: Resolving deltas: 100% (19/19), done.</div><div class="line">To https://git.coding.net/da_/zcll.git</div><div class="line">   857afd6..252f11c  master -&gt; master</div><div class="line">Branch master set up to track remote branch master from zcll.</div></pre></td></tr></table></figure>
<a id="more"></a>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;在服务器创建好后  应该先拉到本地 再推。&lt;/p&gt;
&lt;p&gt;提前推是会报错的。&lt;/p&gt;
&lt;p&gt;如果本地已经创建项目  需要合并下。&lt;/p&gt;
&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;18&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;19&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;20&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;21&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;22&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;23&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;24&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;25&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;26&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;27&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;28&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;29&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;30&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;31&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;32&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;33&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;34&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;35&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;36&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;H:\zcll&amp;gt;git remote add zcll https://git.coding.net/da_/zcll.git&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;H:\zcll&amp;gt;git push -u zcll master&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;To https://git.coding.net/da_/zcll.git&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; ! [rejected]        master -&amp;gt; master (non-fast-forward)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;error: failed to push some refs to &amp;apos;https://git.coding.net/da_/zcll.git&amp;apos;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;hint: Updates were rejected because the tip of your current branch is behind&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;hint: its remote counterpart. Integrate the remote changes (e.g.&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;hint: &amp;apos;git pull ...&amp;apos;) before pushing again.&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;hint: See the &amp;apos;Note about fast-forwards&amp;apos; in &amp;apos;git push --help&amp;apos; for details.&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;H:\zcll&amp;gt;git pull zcll master&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;From https://git.coding.net/da_/zcll&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; * branch            master     -&amp;gt; FETCH_HEAD&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;fatal: refusing to merge unrelated histories&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;H:\zcll&amp;gt;git pull zcll master  --allow-unrelated-histories&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;From https://git.coding.net/da_/zcll&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; * branch            master     -&amp;gt; FETCH_HEAD&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;Merge made by the &amp;apos;recursive&amp;apos; strategy.&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; README.md | 1 +&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; 1 file changed, 1 insertion(+)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; create mode 100644 README.md&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;H:\zcll&amp;gt;git push -u zcll master&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;Counting objects: 148, done.&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;Delta compression using up to 4 threads.&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;Compressing objects: 100% (140/140), done.&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;Writing objects: 100% (148/148), 3.35 MiB | 673.00 KiB/s, done.&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;Total 148 (delta 19), reused 0 (delta 0)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;remote: Resolving deltas: 100% (19/19), done.&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;To https://git.coding.net/da_/zcll.git&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;   857afd6..252f11c  master -&amp;gt; master&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;Branch master set up to track remote branch master from zcll.&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
    
    </summary>
    
      <category term="git" scheme="http://sunhao.win/categories/git/"/>
    
    
      <category term="git" scheme="http://sunhao.win/tags/git/"/>
    
  </entry>
  
  <entry>
    <title>js-Class.js学习 源码分析</title>
    <link href="http://sunhao.win/articles/js-Class-js.html"/>
    <id>http://sunhao.win/articles/js-Class-js.html</id>
    <published>2017-10-26T02:20:26.000Z</published>
    <updated>2017-10-27T01:58:31.771Z</updated>
    
    <content type="html"><![CDATA[<h3 id="学习"><a href="#学习" class="headerlink" title="学习"></a>学习</h3><p>以下学习需要面向对象基础知识和prototype继承了解</p>
<h4 id="什么是继承"><a href="#什么是继承" class="headerlink" title="什么是继承"></a>什么是继承</h4><p>ClassJs提供了完整的继承机制。</p>
<p>为什么要继承</p>
<p>因为父类的功能是不完善的，随着项目的迭代，性能功能上明显不足。</p>
<p>这个时候多个项目栏目可能依赖这个父类，导致你不能修改。</p>
<p>即使修改也会导致项目错乱，一改全部都改。</p>
<p>所以这个时候为了能达到效率和灵活，我们需要用面向对象继承机制。</p>
<p>父类是不完善的，子类通过继承父类的所有，并对不足的予以修订。</p>
<p>所以继承的任务有两个</p>
<pre><code>1. 子类获取父类所有功能    

2. 子类对父类不足的进行修改
</code></pre><p>继承还有两个特性即单根性和传递性</p>
<pre><code>1. 单根性 （子类只有一个父类）
2. 传递性    （即子类可以作为父类不断传递下去）
</code></pre><h4 id="教程"><a href="#教程" class="headerlink" title="教程"></a>教程</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//首先我们通过Class.extend创造基类person，</span></div><div class="line"><span class="keyword">var</span> Person = Class.extend(&#123; </div><div class="line">  <span class="attr">init</span>: <span class="function"><span class="keyword">function</span>(<span class="params">isDancing</span>)</span>&#123; </div><div class="line">    <span class="keyword">this</span>.dancing = isDancing; </div><div class="line">  &#125;, </div><div class="line">  <span class="attr">dance</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123; </div><div class="line">    <span class="keyword">return</span> <span class="keyword">this</span>.dancing; </div><div class="line">  &#125; </div><div class="line">&#125;); </div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">var</span> Ninja = Person.extend(&#123; </div><div class="line">  <span class="attr">init</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123; </div><div class="line">    <span class="keyword">this</span>._super( <span class="literal">false</span> ); </div><div class="line">  &#125;, </div><div class="line">  <span class="attr">dance</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123; </div><div class="line">    <span class="comment">// Call the inherited version of dance() </span></div><div class="line">    <span class="keyword">return</span> <span class="keyword">this</span>._super(); </div><div class="line">  &#125;, </div><div class="line">  <span class="attr">swingSword</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123; </div><div class="line">    <span class="keyword">return</span> <span class="literal">true</span>; </div><div class="line">  &#125; </div><div class="line">&#125;); </div><div class="line"></div><div class="line"><span class="keyword">var</span> p = <span class="keyword">new</span> Person(<span class="literal">true</span>); </div><div class="line">p.dance(); <span class="comment">// =&gt; true </span></div><div class="line"></div><div class="line"><span class="keyword">var</span> n = <span class="keyword">new</span> Ninja(); </div><div class="line">n.dance(); <span class="comment">// =&gt; false </span></div><div class="line">n.swingSword(); <span class="comment">// =&gt; true</span></div></pre></td></tr></table></figure>
<p>首先用Class.extend创建基类Person并传入prototype<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&#123; </div><div class="line">  //prototype</div><div class="line">  init: function(isDancing)&#123; </div><div class="line">    this.dancing = isDancing; </div><div class="line">  &#125;, </div><div class="line">  dance: function()&#123; </div><div class="line">    return this.dancing; </div><div class="line">  &#125; </div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>因为js没有纯正的面向对象机制，所谓的继承是由prototype来实现。</p>
<p>当执行完Class.extend并传入prototype会返回一个构造函数给Person。这个函数的构造体是我们的Class的构造函数，prototype是我们传入的值。所以返回的构造函数，打印出来会是这样。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">console</span>.dir(Person)</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">Class</span>(<span class="params"></span>)</span></div><div class="line">	<span class="title">arguments</span>:<span class="title">null</span></div><div class="line">	<span class="title">caller</span>:<span class="title">null</span></div><div class="line">	<span class="title">extend</span>:<span class="title">function</span>(<span class="params">prop</span>)</div><div class="line">	<span class="title">inject</span>:<span class="title">function</span>(<span class="params">prop</span>)</div><div class="line">	<span class="title">length</span>:0</div><div class="line">	<span class="title">name</span>:"<span class="title">Class</span>"</div><div class="line">	<span class="title">prototype</span>:<span class="title">Class</span></div><div class="line">		<span class="title">constructor</span>:<span class="title">function</span> <span class="title">Class</span>(<span class="params"></span>)</div><div class="line">		<span class="title">dance</span>:<span class="title">function</span>(<span class="params"></span>)</div><div class="line">		<span class="title">init</span>:<span class="title">function</span>(<span class="params">isDancing</span>)</div><div class="line">		<span class="title">__proto__</span>:<span class="title">Object</span></div><div class="line">	<span class="title">__proto__</span>:<span class="title">function</span>(<span class="params"></span>)</div><div class="line">	&lt;<span class="title">function</span> <span class="title">scope</span>&gt;</div></pre></td></tr></table></figure>
<p>当我们运行<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">var p = new Person(true); </div><div class="line">p.dance(); // =&gt; true</div></pre></td></tr></table></figure></p>
<p>把true传入Person那么初始化函数init自动执行，dance所指向的就变成true。<br>这个时候用dance打印当前域的dance就变成了true</p>
<p>这个时候我们运行<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">var Ninja = Person.extend(&#123; </div><div class="line">  init: function()&#123; </div><div class="line">    this._super( false ); </div><div class="line">  &#125;, </div><div class="line">  dance: function()&#123; </div><div class="line">    // Call the inherited version of dance() </div><div class="line">    return this._super(); </div><div class="line">  &#125;, </div><div class="line">  swingSword: function()&#123; </div><div class="line">    return true; </div><div class="line">  &#125; </div><div class="line">&#125;);</div></pre></td></tr></table></figure></p>
<p>用于继承Person这个类</p>
<p>这里的init里面的this._super(false)指向的是父类也就是Person内原型里面的init。<br>子类init和父类init是重名 ，这个时候子类会把对父类传递值得修改，传给父级。即等于<br>this._super( false ) ==  （this.dancing = false; ）</p>
<p>dance同理</p>
<p>swingSword因为父类没有，所以它来源于自己，直接添加到prototype。</p>
<p>所以运行后的Ninja的构造函数是</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="built_in">console</span>.dir(Person)</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">Class</span>(<span class="params"></span>)</span></div><div class="line">	<span class="title">arguments</span>:<span class="title">null</span></div><div class="line">	<span class="title">caller</span>:<span class="title">null</span></div><div class="line">	<span class="title">extend</span>:<span class="title">function</span>(<span class="params">prop</span>)</div><div class="line">	<span class="title">inject</span>:<span class="title">function</span>(<span class="params">prop</span>)</div><div class="line">	<span class="title">length</span>:0</div><div class="line">	<span class="title">name</span>:"<span class="title">Class</span>"</div><div class="line">	<span class="title">prototype</span>:<span class="title">Class</span></div><div class="line">		<span class="title">constructor</span>:<span class="title">function</span> <span class="title">Class</span>(<span class="params"></span>)</div><div class="line">		<span class="title">dance</span>:<span class="title">function</span>(<span class="params"></span>)</div><div class="line">		<span class="title">init</span>:<span class="title">function</span>(<span class="params">isDancing</span>)</div><div class="line">		<span class="title">swingSword</span>：<span class="title">function</span>(<span class="params"></span>)</div><div class="line">		<span class="title">__proto__</span>:<span class="title">Class</span></div><div class="line">	<span class="title">__proto__function</span>:(<span class="params"></span>)</div><div class="line">	&lt;<span class="title">function</span> <span class="title">scope</span>&gt;</div></pre></td></tr></table></figure>
<p>这个时候运行<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">var n = new Ninja(); </div><div class="line">n.dance(); // =&gt; false </div><div class="line">n.swingSword(); // =&gt; true</div></pre></td></tr></table></figure></p>
<p>发现我们的dance变成false  是因为我们修改了原来的类，同时添加了swingSword扩充了父类。</p>
<p>从而实现了继承的特性。</p>
<h3 id="代码分析"><a href="#代码分析" class="headerlink" title="代码分析"></a>代码分析</h3><p>ClassJs用于对象的继承，源代码比较小巧90行左右，非常精简。</p>
<ol>
<li><p>fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;<br> test是为了判断字符串是否匹配。所以大部分浏览器对函数内部的数据如果是函数会执行toString保证运行。<br> 例如</p>
 <figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> a = &#123;&#125;</div><div class="line"><span class="literal">undefined</span></div><div class="line"></div><div class="line">/a/.test(a)</div><div class="line"><span class="literal">false</span></div><div class="line"></div><div class="line">/a/.test(<span class="string">'a'</span>)</div><div class="line"><span class="literal">true</span></div><div class="line"></div><div class="line">/a/.test(<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;a&#125;)</div><div class="line"><span class="literal">true</span></div></pre></td></tr></table></figure>
<p> fnTest这里的目的就是为了判断当前浏览器是否支持函数toString，如果支持返回/\b_super\b/，否则返回 /.*/</p>
</li>
<li><p>首先都在(function(){})()这个自执行里面，防止对全局污染。</p>
</li>
<li><p>然后用 this.Class = function() {};创建构造函数Class.这里的this.Class的this是指向的window</p>
</li>
<li><p>然后是在Class类上添加extend方法，该方法用于实现继承，传入一个prop对象，返回Class的原型+prop对象。下面对Class.extend里面代码分析</p>
<ol>
<li>var _super = this.prototype; 这里 _super就是Class的原型。用于保存原型。</li>
<li><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">initializing = true;</div><div class="line">var prototype = new this();</div><div class="line">initializing = false;</div></pre></td></tr></table></figure>
<p>这三段用于初始化，把实例化的Class赋值给prototype</p>
</li>
</ol>
</li>
<li><p>这是一段for循环用于把prop的属性复制给prototype</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">for</span> (<span class="keyword">var</span> name <span class="keyword">in</span> prop) &#123;</div><div class="line">    <span class="comment">// Check if we're overwriting an existing function </span></div><div class="line">    prototype[name] = <span class="keyword">typeof</span> prop[name] == <span class="string">"function"</span> &amp;&amp;</div><div class="line">        <span class="keyword">typeof</span> _super[name] == <span class="string">"function"</span> &amp;&amp; fnTest.test(prop[name]) ?</div><div class="line">        (<span class="function"><span class="keyword">function</span>(<span class="params">name, fn</span>) </span>&#123;</div><div class="line">            <span class="keyword">return</span> <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</div><div class="line">                <span class="keyword">var</span> tmp = <span class="keyword">this</span>._super;</div><div class="line"></div><div class="line">                <span class="comment">// Add a new ._super() method that is the same method </span></div><div class="line">                <span class="comment">// but on the super-class </span></div><div class="line">                <span class="keyword">this</span>._super = _super[name];</div><div class="line"></div><div class="line">                <span class="comment">// The method only need to be bound temporarily, so we </span></div><div class="line">                <span class="comment">// remove it when we're done executing </span></div><div class="line">                <span class="keyword">var</span> ret = fn.apply(<span class="keyword">this</span>, <span class="built_in">arguments</span>);</div><div class="line">                <span class="keyword">this</span>._super = tmp;</div><div class="line"></div><div class="line">                <span class="keyword">return</span> ret;</div><div class="line">            &#125;;</div><div class="line">        &#125;)(name, prop[name]) :</div><div class="line">        prop[name];</div><div class="line">&#125;</div></pre></td></tr></table></figure>
</li>
</ol>
<p>我们分析下这一段<br> prototype[name] = typeof prop[name] == “function” &amp;&amp; typeof _super[name] == “function” &amp;&amp; fnTest.test(prop[name]) ? (function(name, fn){})(name, prop[name]):prop[name]</p>
<pre><code>1. typeof prop[name] == &quot;function&quot; &amp;&amp; typeof _super[name] == &quot;function&quot; 用于构造函数中的相应name是不是函数，传递过来的prop中的name是不是也是函数。
2. fnTest.test(prop[name]) 同样也是用于判断传来的prop是否有_super。
3. 如果上面两个都是true那么就把
</code></pre><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> Class = &#123;&#125;</div><div class="line"><span class="keyword">var</span> result = &#123;&#125;</div><div class="line">Class.extend =<span class="function"><span class="keyword">function</span>(<span class="params">prop</span>)</span>&#123;</div><div class="line">	<span class="keyword">var</span> _super = <span class="keyword">this</span>.prototype;</div><div class="line">	<span class="keyword">for</span>(<span class="keyword">var</span> name <span class="keyword">in</span> prop)&#123;</div><div class="line">		   result[name] = <span class="regexp">/\b_super\b/</span>.test(prop[name])?(<span class="function"><span class="keyword">function</span>(<span class="params">name, fn</span>) </span>&#123;</div><div class="line">                    <span class="keyword">return</span> <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</div><div class="line">                    	</div><div class="line">                        <span class="keyword">var</span> tmp = <span class="keyword">this</span>._super; <span class="comment">//把super存入tmp缓存防止覆盖</span></div><div class="line">                        <span class="keyword">this</span>._super = _super[name]; <span class="comment">//把super方法复制给super,this._super已经变成父类name函数</span></div><div class="line"></div><div class="line"><span class="comment">//这里我们要运行fn即prop[name]，然后 return this._super指向当前。然后把return this._super();返回值赋值给result即ret </span></div><div class="line"><span class="comment">// dance: function()&#123; </span></div><div class="line"><span class="comment">// </span></div><div class="line"><span class="comment">//   return this._super(); </span></div><div class="line"><span class="comment">// &#125;, </span></div><div class="line"></div><div class="line"><span class="comment">// 例如父级是</span></div><div class="line"></div><div class="line"><span class="comment">//  init: function(isDancing)&#123; </span></div><div class="line"><span class="comment">//     this.dancing = isDancing; </span></div><div class="line"><span class="comment">//   &#125;, </span></div><div class="line"></div><div class="line"><span class="comment">//  子是</span></div><div class="line"><span class="comment">//    init: function()&#123; </span></div><div class="line"><span class="comment">//     this._super( false ); </span></div><div class="line"><span class="comment">//   &#125;, </span></div><div class="line"><span class="comment">//  子实例化的时候会传入false，然后返回ret。。。。简单点就是如果是同名的那就继承。</span></div><div class="line"></div><div class="line"></div><div class="line">                        <span class="keyword">var</span> ret = fn.apply(<span class="keyword">this</span>, <span class="built_in">arguments</span>); </div><div class="line">                        <span class="keyword">this</span>._super = tmp;</div><div class="line"></div><div class="line">                        <span class="keyword">return</span> ret;</div><div class="line">                    &#125;;</div><div class="line">                &#125;)(name, prop[name]):prop[name] <span class="comment">//如果函数体里面有super那么就继承来至父级别。否则直接进行赋值</span></div><div class="line">	&#125;</div><div class="line"></div><div class="line">	<span class="keyword">return</span> </div><div class="line">&#125;</div><div class="line"></div><div class="line"> <span class="keyword">var</span> Person = Class.extend(&#123; </div><div class="line">  <span class="attr">init</span>: <span class="function"><span class="keyword">function</span>(<span class="params">isDancing</span>)</span>&#123; </div><div class="line">    <span class="keyword">this</span>.dancing = isDancing; </div><div class="line">  &#125;, </div><div class="line">  <span class="attr">dance</span>: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123; </div><div class="line">    <span class="keyword">return</span> <span class="keyword">this</span>.dancing; </div><div class="line">  &#125; </div><div class="line">&#125;);</div></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div></pre></td><td class="code"><pre><div class="line">(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</div><div class="line">    <span class="keyword">var</span> fnTest = <span class="regexp">/xyz/</span>.test(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123; xyz; &#125;) ? <span class="regexp">/\b_super\b/</span> : <span class="regexp">/.*/</span>;</div><div class="line"></div><div class="line">    <span class="comment">// The base Class implementation (does nothing) </span></div><div class="line">    <span class="keyword">this</span>.Class = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;&#125;;</div><div class="line"></div><div class="line"></div><div class="line">    <span class="comment">// Create a new Class that inherits from this class </span></div><div class="line">    Class.extend = <span class="function"><span class="keyword">function</span>(<span class="params">prop</span>) </span>&#123;</div><div class="line">        <span class="keyword">var</span> _super = <span class="keyword">this</span>.prototype;</div><div class="line"></div><div class="line">        <span class="comment">// Instantiate a base class (but only create the instance, </span></div><div class="line">        <span class="comment">// don't run the init constructor) </span></div><div class="line">        initializing = <span class="literal">true</span>;</div><div class="line">        <span class="keyword">var</span> prototype = <span class="keyword">new</span> <span class="keyword">this</span>();</div><div class="line">        initializing = <span class="literal">false</span>;</div><div class="line"></div><div class="line"></div><div class="line">        <span class="comment">// Copy the properties over onto the new prototype </span></div><div class="line">        <span class="keyword">for</span> (<span class="keyword">var</span> name <span class="keyword">in</span> prop) &#123;</div><div class="line">            <span class="comment">// Check if we're overwriting an existing function </span></div><div class="line">            prototype[name] = <span class="keyword">typeof</span> prop[name] == <span class="string">"function"</span> &amp;&amp;</div><div class="line">                <span class="keyword">typeof</span> _super[name] == <span class="string">"function"</span> &amp;&amp; fnTest.test(prop[name]) ?</div><div class="line">                (<span class="function"><span class="keyword">function</span>(<span class="params">name, fn</span>) </span>&#123;</div><div class="line">                    <span class="keyword">return</span> <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</div><div class="line">                        <span class="keyword">var</span> tmp = <span class="keyword">this</span>._super;</div><div class="line"></div><div class="line">                        <span class="comment">// Add a new ._super() method that is the same method </span></div><div class="line">                        <span class="comment">// but on the super-class </span></div><div class="line">                        <span class="keyword">this</span>._super = _super[name];</div><div class="line"></div><div class="line">                        <span class="comment">// The method only need to be bound temporarily, so we </span></div><div class="line">                        <span class="comment">// remove it when we're done executing </span></div><div class="line">                        <span class="keyword">var</span> ret = fn.apply(<span class="keyword">this</span>, <span class="built_in">arguments</span>);</div><div class="line">                        <span class="keyword">this</span>._super = tmp;</div><div class="line"></div><div class="line">                        <span class="keyword">return</span> ret;</div><div class="line">                    &#125;;</div><div class="line">                &#125;)(name, prop[name]) :</div><div class="line">                prop[name];</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="comment">// The dummy class constructor </span></div><div class="line">        <span class="function"><span class="keyword">function</span> <span class="title">Class</span>(<span class="params"></span>) </span>&#123;</div><div class="line">            <span class="comment">// All construction is actually done in the init method </span></div><div class="line">            <span class="keyword">if</span> (!initializing &amp;&amp; <span class="keyword">this</span>.init)</div><div class="line">                <span class="keyword">this</span>.init.apply(<span class="keyword">this</span>, <span class="built_in">arguments</span>);</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="comment">// Populate our constructed prototype object </span></div><div class="line">        Class.prototype = prototype;</div><div class="line"></div><div class="line">        <span class="comment">// Enforce the constructor to be what we expect </span></div><div class="line">        Class.prototype.constructor = Class;</div><div class="line"></div><div class="line">        <span class="comment">// And make this class extendable </span></div><div class="line">        Class.extend = <span class="built_in">arguments</span>.callee;</div><div class="line"></div><div class="line">        <span class="comment">// EXTENSION BY Draw2D.org to inject methods into an existing class to provide plugins or </span></div><div class="line">        <span class="comment">// bugfixes for further releases </span></div><div class="line">        <span class="comment">// </span></div><div class="line">        Class.inject = <span class="function"><span class="keyword">function</span>(<span class="params">prop</span>) </span>&#123;</div><div class="line">            <span class="keyword">var</span> proto = <span class="keyword">this</span>.prototype;</div><div class="line">            <span class="keyword">var</span> parent = &#123;&#125;;</div><div class="line">            <span class="keyword">for</span> (<span class="keyword">var</span> name <span class="keyword">in</span> prop) &#123;</div><div class="line">                <span class="keyword">if</span> (<span class="keyword">typeof</span>(prop[name]) == <span class="string">"function"</span> &amp;&amp; <span class="keyword">typeof</span>(proto[name]) == <span class="string">"function"</span> &amp;&amp; fnTest.test(prop[name])) &#123;</div><div class="line">                    parent[name] = proto[name];</div><div class="line">                    proto[name] = (<span class="function"><span class="keyword">function</span>(<span class="params">name, fn</span>) </span>&#123;</div><div class="line">                        <span class="keyword">return</span> <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</div><div class="line">                            <span class="keyword">var</span> tmp = <span class="keyword">this</span>.parent;</div><div class="line">                            <span class="keyword">this</span>.parent = parent[name];</div><div class="line">                            <span class="keyword">var</span> ret = fn.apply(<span class="keyword">this</span>, <span class="built_in">arguments</span>);</div><div class="line">                            <span class="keyword">this</span>.parent = tmp;</div><div class="line">                            <span class="keyword">return</span> ret;</div><div class="line">                        &#125;;</div><div class="line">                    &#125;)(name, prop[name]);</div><div class="line">                &#125; <span class="keyword">else</span> &#123;</div><div class="line">                    proto[name] = prop[name];</div><div class="line">                &#125;</div><div class="line">            &#125;</div><div class="line">        &#125;;</div><div class="line"></div><div class="line">        <span class="keyword">return</span> Class;</div><div class="line">    &#125;;</div><div class="line">&#125;)();</div></pre></td></tr></table></figure>
<a id="more"></a>]]></content>
    
    <summary type="html">
    
      &lt;h3 id=&quot;学习&quot;&gt;&lt;a href=&quot;#学习&quot; class=&quot;headerlink&quot; title=&quot;学习&quot;&gt;&lt;/a&gt;学习&lt;/h3&gt;&lt;p&gt;以下学习需要面向对象基础知识和prototype继承了解&lt;/p&gt;
&lt;h4 id=&quot;什么是继承&quot;&gt;&lt;a href=&quot;#什么是继承&quot; class=&quot;headerlink&quot; title=&quot;什么是继承&quot;&gt;&lt;/a&gt;什么是继承&lt;/h4&gt;&lt;p&gt;ClassJs提供了完整的继承机制。&lt;/p&gt;
&lt;p&gt;为什么要继承&lt;/p&gt;
&lt;p&gt;因为父类的功能是不完善的，随着项目的迭代，性能功能上明显不足。&lt;/p&gt;
&lt;p&gt;这个时候多个项目栏目可能依赖这个父类，导致你不能修改。&lt;/p&gt;
&lt;p&gt;即使修改也会导致项目错乱，一改全部都改。&lt;/p&gt;
&lt;p&gt;所以这个时候为了能达到效率和灵活，我们需要用面向对象继承机制。&lt;/p&gt;
&lt;p&gt;父类是不完善的，子类通过继承父类的所有，并对不足的予以修订。&lt;/p&gt;
&lt;p&gt;所以继承的任务有两个&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;1. 子类获取父类所有功能    

2. 子类对父类不足的进行修改
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;继承还有两个特性即单根性和传递性&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;1. 单根性 （子类只有一个父类）
2. 传递性    （即子类可以作为父类不断传递下去）
&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;教程&quot;&gt;&lt;a href=&quot;#教程&quot; class=&quot;headerlink&quot; title=&quot;教程&quot;&gt;&lt;/a&gt;教程&lt;/h4&gt;&lt;figure class=&quot;highlight javascript&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;18&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;19&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;20&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;21&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;22&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;23&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;24&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;25&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;26&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;27&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;28&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;29&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;30&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;31&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//首先我们通过Class.extend创造基类person，&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; Person = Class.extend(&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attr&quot;&gt;init&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;isDancing&lt;/span&gt;)&lt;/span&gt;&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.dancing = isDancing; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attr&quot;&gt;dance&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/span&gt;&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.dancing; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;); &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; Ninja = Person.extend(&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attr&quot;&gt;init&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/span&gt;&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;._super( &lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt; ); &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attr&quot;&gt;dance&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/span&gt;&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;comment&quot;&gt;// Call the inherited version of dance() &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;._super(); &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attr&quot;&gt;swingSword&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/span&gt;&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;); &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; p = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Person(&lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;); &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;p.dance(); &lt;span class=&quot;comment&quot;&gt;// =&amp;gt; true &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; n = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Ninja(); &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;n.dance(); &lt;span class=&quot;comment&quot;&gt;// =&amp;gt; false &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;n.swingSword(); &lt;span class=&quot;comment&quot;&gt;// =&amp;gt; true&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;首先用Class.extend创建基类Person并传入prototype&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  //prototype&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  init: function(isDancing)&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    this.dancing = isDancing; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  dance: function()&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    return this.dancing; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;因为js没有纯正的面向对象机制，所谓的继承是由prototype来实现。&lt;/p&gt;
&lt;p&gt;当执行完Class.extend并传入prototype会返回一个构造函数给Person。这个函数的构造体是我们的Class的构造函数，prototype是我们传入的值。所以返回的构造函数，打印出来会是这样。&lt;/p&gt;
&lt;figure class=&quot;highlight javascript&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.dir(Person)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;Class&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;arguments&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;null&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;caller&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;null&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;extend&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;prop&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;inject&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;prop&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;length&lt;/span&gt;:0&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;name&lt;/span&gt;:&quot;&lt;span class=&quot;title&quot;&gt;Class&lt;/span&gt;&quot;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;prototype&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;Class&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;		&lt;span class=&quot;title&quot;&gt;constructor&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;Class&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;		&lt;span class=&quot;title&quot;&gt;dance&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;		&lt;span class=&quot;title&quot;&gt;init&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;isDancing&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;		&lt;span class=&quot;title&quot;&gt;__proto__&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;Object&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;__proto__&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&amp;lt;&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;scope&lt;/span&gt;&amp;gt;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;当我们运行&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;var p = new Person(true); &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;p.dance(); // =&amp;gt; true&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;把true传入Person那么初始化函数init自动执行，dance所指向的就变成true。&lt;br&gt;这个时候用dance打印当前域的dance就变成了true&lt;/p&gt;
&lt;p&gt;这个时候我们运行&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;var Ninja = Person.extend(&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  init: function()&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    this._super( false ); &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  dance: function()&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    // Call the inherited version of dance() &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    return this._super(); &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  swingSword: function()&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    return true; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;);&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;用于继承Person这个类&lt;/p&gt;
&lt;p&gt;这里的init里面的this._super(false)指向的是父类也就是Person内原型里面的init。&lt;br&gt;子类init和父类init是重名 ，这个时候子类会把对父类传递值得修改，传给父级。即等于&lt;br&gt;this._super( false ) ==  （this.dancing = false; ）&lt;/p&gt;
&lt;p&gt;dance同理&lt;/p&gt;
&lt;p&gt;swingSword因为父类没有，所以它来源于自己，直接添加到prototype。&lt;/p&gt;
&lt;p&gt;所以运行后的Ninja的构造函数是&lt;/p&gt;
&lt;figure class=&quot;highlight javascript&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.dir(Person)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;Class&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;arguments&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;null&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;caller&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;null&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;extend&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;prop&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;inject&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;prop&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;length&lt;/span&gt;:0&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;name&lt;/span&gt;:&quot;&lt;span class=&quot;title&quot;&gt;Class&lt;/span&gt;&quot;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;prototype&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;Class&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;		&lt;span class=&quot;title&quot;&gt;constructor&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;Class&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;		&lt;span class=&quot;title&quot;&gt;dance&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;		&lt;span class=&quot;title&quot;&gt;init&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;isDancing&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;		&lt;span class=&quot;title&quot;&gt;swingSword&lt;/span&gt;：&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;		&lt;span class=&quot;title&quot;&gt;__proto__&lt;/span&gt;:&lt;span class=&quot;title&quot;&gt;Class&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;title&quot;&gt;__proto__function&lt;/span&gt;:(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&amp;lt;&lt;span class=&quot;title&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;scope&lt;/span&gt;&amp;gt;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;这个时候运行&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;var n = new Ninja(); &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;n.dance(); // =&amp;gt; false &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;n.swingSword(); // =&amp;gt; true&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;发现我们的dance变成false  是因为我们修改了原来的类，同时添加了swingSword扩充了父类。&lt;/p&gt;
&lt;p&gt;从而实现了继承的特性。&lt;/p&gt;
&lt;h3 id=&quot;代码分析&quot;&gt;&lt;a href=&quot;#代码分析&quot; class=&quot;headerlink&quot; title=&quot;代码分析&quot;&gt;&lt;/a&gt;代码分析&lt;/h3&gt;&lt;p&gt;ClassJs用于对象的继承，源代码比较小巧90行左右，非常精简。&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;&lt;br&gt; test是为了判断字符串是否匹配。所以大部分浏览器对函数内部的数据如果是函数会执行toString保证运行。&lt;br&gt; 例如&lt;/p&gt;
 &lt;figure class=&quot;highlight javascript&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; a = &amp;#123;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;literal&quot;&gt;undefined&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;/a/.test(a)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;/a/.test(&lt;span class=&quot;string&quot;&gt;&#39;a&#39;&lt;/span&gt;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;/a/.test(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/span&gt;&amp;#123;a&amp;#125;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt; fnTest这里的目的就是为了判断当前浏览器是否支持函数toString，如果支持返回/\b_super\b/，否则返回 /.*/&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;首先都在(function(){})()这个自执行里面，防止对全局污染。&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;然后用 this.Class = function() {};创建构造函数Class.这里的this.Class的this是指向的window&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;然后是在Class类上添加extend方法，该方法用于实现继承，传入一个prop对象，返回Class的原型+prop对象。下面对Class.extend里面代码分析&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;var _super = this.prototype; 这里 _super就是Class的原型。用于保存原型。&lt;/li&gt;
&lt;li&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;initializing = true;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;var prototype = new this();&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;initializing = false;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;这三段用于初始化，把实例化的Class赋值给prototype&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;这是一段for循环用于把prop的属性复制给prototype&lt;/p&gt;
&lt;figure class=&quot;highlight javascript&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;18&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;19&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;20&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;21&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;22&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; name &lt;span class=&quot;keyword&quot;&gt;in&lt;/span&gt; prop) &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;comment&quot;&gt;// Check if we&#39;re overwriting an existing function &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    prototype[name] = &lt;span class=&quot;keyword&quot;&gt;typeof&lt;/span&gt; prop[name] == &lt;span class=&quot;string&quot;&gt;&quot;function&quot;&lt;/span&gt; &amp;amp;&amp;amp;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;keyword&quot;&gt;typeof&lt;/span&gt; _super[name] == &lt;span class=&quot;string&quot;&gt;&quot;function&quot;&lt;/span&gt; &amp;amp;&amp;amp; fnTest.test(prop[name]) ?&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        (&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;name, fn&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; tmp = &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;._super;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;comment&quot;&gt;// Add a new ._super() method that is the same method &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;comment&quot;&gt;// but on the super-class &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;._super = _super[name];&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;comment&quot;&gt;// The method only need to be bound temporarily, so we &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;comment&quot;&gt;// remove it when we&#39;re done executing &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; ret = fn.apply(&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;, &lt;span class=&quot;built_in&quot;&gt;arguments&lt;/span&gt;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;._super = tmp;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; ret;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &amp;#125;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &amp;#125;)(name, prop[name]) :&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        prop[name];&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;我们分析下这一段&lt;br&gt; prototype[name] = typeof prop[name] == “function” &amp;amp;&amp;amp; typeof _super[name] == “function” &amp;amp;&amp;amp; fnTest.test(prop[name]) ? (function(name, fn){})(name, prop[name]):prop[name]&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;1. typeof prop[name] == &amp;quot;function&amp;quot; &amp;amp;&amp;amp; typeof _super[name] == &amp;quot;function&amp;quot; 用于构造函数中的相应name是不是函数，传递过来的prop中的name是不是也是函数。
2. fnTest.test(prop[name]) 同样也是用于判断传来的prop是否有_super。
3. 如果上面两个都是true那么就把
&lt;/code&gt;&lt;/pre&gt;&lt;figure class=&quot;highlight javascript&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;18&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;19&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;20&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;21&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;22&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;23&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;24&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;25&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;26&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;27&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;28&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;29&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;30&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;31&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;32&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;33&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;34&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;35&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;36&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;37&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;38&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;39&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;40&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;41&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;42&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;43&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;44&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;45&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;46&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;47&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;48&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;49&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; Class = &amp;#123;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; result = &amp;#123;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;Class.extend =&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;prop&lt;/span&gt;)&lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; _super = &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.prototype;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt;(&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; name &lt;span class=&quot;keyword&quot;&gt;in&lt;/span&gt; prop)&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;		   result[name] = &lt;span class=&quot;regexp&quot;&gt;/\b_super\b/&lt;/span&gt;.test(prop[name])?(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;name, fn&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                    	&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; tmp = &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;._super; &lt;span class=&quot;comment&quot;&gt;//把super存入tmp缓存防止覆盖&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;._super = _super[name]; &lt;span class=&quot;comment&quot;&gt;//把super方法复制给super,this._super已经变成父类name函数&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//这里我们要运行fn即prop[name]，然后 return this._super指向当前。然后把return this._super();返回值赋值给result即ret &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// dance: function()&amp;#123; &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//   return this._super(); &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// &amp;#125;, &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;// 例如父级是&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//  init: function(isDancing)&amp;#123; &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//     this.dancing = isDancing; &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//   &amp;#125;, &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//  子是&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//    init: function()&amp;#123; &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//     this._super( false ); &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//   &amp;#125;, &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;//  子实例化的时候会传入false，然后返回ret。。。。简单点就是如果是同名的那就继承。&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; ret = fn.apply(&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;, &lt;span class=&quot;built_in&quot;&gt;arguments&lt;/span&gt;); &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;._super = tmp;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; ret;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                    &amp;#125;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &amp;#125;)(name, prop[name]):prop[name] &lt;span class=&quot;comment&quot;&gt;//如果函数体里面有super那么就继承来至父级别。否则直接进行赋值&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;	&lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; Person = Class.extend(&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attr&quot;&gt;init&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;isDancing&lt;/span&gt;)&lt;/span&gt;&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.dancing = isDancing; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attr&quot;&gt;dance&lt;/span&gt;: &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;)&lt;/span&gt;&amp;#123; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.dancing; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;);&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;figure class=&quot;highlight javascript&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;18&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;19&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;20&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;21&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;22&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;23&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;24&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;25&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;26&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;27&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;28&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;29&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;30&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;31&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;32&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;33&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;34&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;35&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;36&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;37&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;38&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;39&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;40&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;41&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;42&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;43&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;44&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;45&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;46&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;47&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;48&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;49&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;50&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;51&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;52&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;53&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;54&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;55&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;56&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;57&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;58&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;59&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;60&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;61&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;62&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;63&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;64&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;65&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;66&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;67&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;68&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;69&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;70&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;71&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;72&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;73&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;74&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;75&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;76&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;77&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;78&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;79&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;80&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;81&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;82&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;83&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;84&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;85&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; fnTest = &lt;span class=&quot;regexp&quot;&gt;/xyz/&lt;/span&gt;.test(&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;&amp;#123; xyz; &amp;#125;) ? &lt;span class=&quot;regexp&quot;&gt;/\b_super\b/&lt;/span&gt; : &lt;span class=&quot;regexp&quot;&gt;/.*/&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;comment&quot;&gt;// The base Class implementation (does nothing) &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.Class = &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;&amp;#123;&amp;#125;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;comment&quot;&gt;// Create a new Class that inherits from this class &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    Class.extend = &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;prop&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; _super = &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.prototype;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;comment&quot;&gt;// Instantiate a base class (but only create the instance, &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;comment&quot;&gt;// don&#39;t run the init constructor) &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        initializing = &lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; prototype = &lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;();&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        initializing = &lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;comment&quot;&gt;// Copy the properties over onto the new prototype &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; name &lt;span class=&quot;keyword&quot;&gt;in&lt;/span&gt; prop) &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &lt;span class=&quot;comment&quot;&gt;// Check if we&#39;re overwriting an existing function &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            prototype[name] = &lt;span class=&quot;keyword&quot;&gt;typeof&lt;/span&gt; prop[name] == &lt;span class=&quot;string&quot;&gt;&quot;function&quot;&lt;/span&gt; &amp;amp;&amp;amp;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;keyword&quot;&gt;typeof&lt;/span&gt; _super[name] == &lt;span class=&quot;string&quot;&gt;&quot;function&quot;&lt;/span&gt; &amp;amp;&amp;amp; fnTest.test(prop[name]) ?&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                (&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;name, fn&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; tmp = &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;._super;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;comment&quot;&gt;// Add a new ._super() method that is the same method &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;comment&quot;&gt;// but on the super-class &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;._super = _super[name];&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;comment&quot;&gt;// The method only need to be bound temporarily, so we &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;comment&quot;&gt;// remove it when we&#39;re done executing &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; ret = fn.apply(&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;, &lt;span class=&quot;built_in&quot;&gt;arguments&lt;/span&gt;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;._super = tmp;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; ret;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                    &amp;#125;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &amp;#125;)(name, prop[name]) :&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                prop[name];&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;comment&quot;&gt;// The dummy class constructor &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;title&quot;&gt;Class&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &lt;span class=&quot;comment&quot;&gt;// All construction is actually done in the init method &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (!initializing &amp;amp;&amp;amp; &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.init)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.init.apply(&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;, &lt;span class=&quot;built_in&quot;&gt;arguments&lt;/span&gt;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;comment&quot;&gt;// Populate our constructed prototype object &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        Class.prototype = prototype;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;comment&quot;&gt;// Enforce the constructor to be what we expect &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        Class.prototype.constructor = Class;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;comment&quot;&gt;// And make this class extendable &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        Class.extend = &lt;span class=&quot;built_in&quot;&gt;arguments&lt;/span&gt;.callee;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;comment&quot;&gt;// EXTENSION BY Draw2D.org to inject methods into an existing class to provide plugins or &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;comment&quot;&gt;// bugfixes for further releases &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;comment&quot;&gt;// &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        Class.inject = &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;prop&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; proto = &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.prototype;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; parent = &amp;#123;&amp;#125;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; name &lt;span class=&quot;keyword&quot;&gt;in&lt;/span&gt; prop) &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;keyword&quot;&gt;typeof&lt;/span&gt;(prop[name]) == &lt;span class=&quot;string&quot;&gt;&quot;function&quot;&lt;/span&gt; &amp;amp;&amp;amp; &lt;span class=&quot;keyword&quot;&gt;typeof&lt;/span&gt;(proto[name]) == &lt;span class=&quot;string&quot;&gt;&quot;function&quot;&lt;/span&gt; &amp;amp;&amp;amp; fnTest.test(prop[name])) &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                    parent[name] = proto[name];&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                    proto[name] = (&lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;name, fn&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;function&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;function&lt;/span&gt;(&lt;span class=&quot;params&quot;&gt;&lt;/span&gt;) &lt;/span&gt;&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                            &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; tmp = &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.parent;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                            &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.parent = parent[name];&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                            &lt;span class=&quot;keyword&quot;&gt;var&lt;/span&gt; ret = fn.apply(&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;, &lt;span class=&quot;built_in&quot;&gt;arguments&lt;/span&gt;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                            &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.parent = tmp;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                            &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; ret;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                        &amp;#125;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                    &amp;#125;)(name, prop[name]);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &amp;#125; &lt;span class=&quot;keyword&quot;&gt;else&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                    proto[name] = prop[name];&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                &amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &amp;#125;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; Class;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &amp;#125;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;)();&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
    
    </summary>
    
      <category term="javascript" scheme="http://sunhao.win/categories/javascript/"/>
    
    
      <category term="javascript" scheme="http://sunhao.win/tags/javascript/"/>
    
      <category term="ClassJs" scheme="http://sunhao.win/tags/ClassJs/"/>
    
      <category term="study" scheme="http://sunhao.win/tags/study/"/>
    
  </entry>
  
  <entry>
    <title>laravel-migration</title>
    <link href="http://sunhao.win/articles/laravel-migration.html"/>
    <id>http://sunhao.win/articles/laravel-migration.html</id>
    <published>2017-09-25T07:21:53.000Z</published>
    <updated>2017-09-26T03:40:49.019Z</updated>
    
    <content type="html"><![CDATA[<p>php artisan make:migration wechat_admin –create=admin</p>
<p>php artisan make:migration  create_user<strong>NAME</strong>     后面跟行为  和表名<br><a id="more"></a></p>
<p>错误信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[Illuminate\Database\QueryException]</div><div class="line">SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email))</div><div class="line"></div><div class="line">[PDOException]</div><div class="line">SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes</div></pre></td></tr></table></figure></p>
<p>原因<br>laravel匹配的是新版本的mysql.而旧版本的mysql长度不够。</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;?php</span></div><div class="line"></div><div class="line"><span class="keyword">namespace</span> <span class="title">App</span>\<span class="title">Providers</span>;</div><div class="line"></div><div class="line"><span class="keyword">use</span> <span class="title">Illuminate</span>\<span class="title">Support</span>\<span class="title">ServiceProvider</span>;</div><div class="line"><span class="keyword">use</span> <span class="title">Illuminate</span>\<span class="title">Support</span>\<span class="title">Facades</span>\<span class="title">Schema</span>;</div><div class="line"></div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">AppServiceProvider</span> <span class="keyword">extends</span> <span class="title">ServiceProvider</span></span></div><div class="line">&#123;</div><div class="line">    <span class="comment">/**</span></div><div class="line">     * Bootstrap any application services.</div><div class="line">     *</div><div class="line">     * <span class="doctag">@return</span> void</div><div class="line">     */</div><div class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">boot</span><span class="params">()</span></span></div><div class="line">    &#123;</div><div class="line">        Schema::defaultStringLength(<span class="number">191</span>);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * Register any application services.</div><div class="line">     *</div><div class="line">     * <span class="doctag">@return</span> void</div><div class="line">     */</div><div class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">register</span><span class="params">()</span></span></div><div class="line">    &#123;</div><div class="line">        <span class="comment">//</span></div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>Error Base table or view already exists: 1050 Table ‘users’ already exists</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div></pre></td><td class="code"><pre><div class="line">&lt;?php</div><div class="line"></div><div class="line">use Illuminate\Support\Facades\Schema;</div><div class="line">use Illuminate\Database\Schema\Blueprint;</div><div class="line">use Illuminate\Database\Migrations\Migration;</div><div class="line"></div><div class="line">class CreateUsersTable extends Migration</div><div class="line">&#123;</div><div class="line">    /**</div><div class="line">     * Run the migrations.</div><div class="line">     *</div><div class="line">     * @return void</div><div class="line">     */</div><div class="line">    public function up()</div><div class="line">    &#123;</div><div class="line">        Schema::dropIfExists(&apos;users&apos;);</div><div class="line">        Schema::create(&apos;users&apos;, function (Blueprint $table) &#123;</div><div class="line">            $table-&gt;increments(&apos;id&apos;);</div><div class="line">            $table-&gt;string(&apos;name&apos;);</div><div class="line">            $table-&gt;string(&apos;email&apos;)-&gt;unique();</div><div class="line">            $table-&gt;string(&apos;password&apos;);</div><div class="line">            $table-&gt;rememberToken();</div><div class="line">            $table-&gt;timestamps();</div><div class="line">        &#125;);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    /**</div><div class="line">     * Reverse the migrations.</div><div class="line">     *</div><div class="line">     * @return void</div><div class="line">     */</div><div class="line">    public function down()</div><div class="line">    &#123;</div><div class="line">        Schema::dropIfExists(&apos;users&apos;);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>第一种，如果刚刚建立起table，并没有数据，可以选择rollback或者reset，即使用</p>
<p>$ php artisan migrate:rollback<br>1<br>或者</p>
<p>$ php artisan migrate:refresh<br>1<br>值得注意的是，rollback这个命令默认选项只会向之前恢复一次migration，而refresh将会把所有migration全部重置，相当于</p>
<p>$ php artisan migrate:reset<br>$ php artisan migrate</p>
<p>如果迁移已经执行，先回滚<br>php artisan migrate:rollback</p>
<p>然后删除迁移文件，运行<br>composer dump-autoload</p>
<p>php artisan migrate:reset</p>
]]></content>
    
    <summary type="html">
    
      &lt;p&gt;php artisan make:migration wechat_admin –create=admin&lt;/p&gt;
&lt;p&gt;php artisan make:migration  create_user&lt;strong&gt;NAME&lt;/strong&gt;     后面跟行为  和表名&lt;br&gt;
    
    </summary>
    
    
  </entry>
  
  <entry>
    <title>子网掩码怎么理解？</title>
    <link href="http://sunhao.win/articles/netwrok-ip-netmask.html"/>
    <id>http://sunhao.win/articles/netwrok-ip-netmask.html</id>
    <published>2017-08-29T08:08:14.000Z</published>
    <updated>2017-09-05T01:03:36.808Z</updated>
    
    <content type="html"><![CDATA[<p>掩码的作用是划分区域</p>
<p>子网掩码使用与IP相同的编址格式，子网掩码为1的部分对应于IP地址的网络与子网部分，子网掩码为0的部分对应于IP地址的主机部分。将子网掩码和IP地址作”与”操作后，IP地址的主机部分将被丢弃，剩余的是网络地址和子网地址。例如，一个IP分组的目的IP地址为：10.2.2.1，若子网掩码为：255.255.255.0，与之作”与”运算得：10.2.2.0，则网络设备认为该IP地址的网络号与子网号为：10.2.2.0。</p>
<p>内网中192.168.1.199的前三组是网络号，后一组是主机号，子网掩码就是255.255.255.0</p>
<p>如果IP同样是192.168.1.199 那么子网掩码可以设成255.255.255.192吗，怎么理解</p>
<p>如果在同一个局域网出现这两种掩码可以相互通讯吗<br><a id="more"></a><br>作者：车小胖<br>链接：<a href="https://www.zhihu.com/question/56895036/answer/150953183" target="_blank" rel="external">https://www.zhihu.com/question/56895036/answer/150953183</a><br>来源：知乎<br>著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。</p>
<p>从前有一个地主，有256间房子，地主家的门牌号码是“192.168.1”，那么他家第一间房子的门牌号码是192.168.1.0，第二间是192.168.1.1，…第256间的编号是192.168.1.255。地主老了，需要把256间房子分给4个儿子，平均分配，每个儿子可以分64间。请来一位先生主持公道，先生这么来操作：192.168.1.0-192.168.1.63 分给大儿子192.168.1.64-192.168.1.127 分给二儿子192.168.1.128 -192.168.1.191 分给三儿子192.168.1.192-192.168.1.255 分给四儿子那如何来描述四个儿子的子网网段呢？192.168.1.0/26192.168.1.64/26192.168.1.128/26192.168.1.192/26/26是什么鬼？255.255.255.192的二进制是多少？ “11111111-11111111-11111111-11”大家数数一共多少个1？不用数了，是26个1，为了简化子网掩码的表示，用/26代替255.255.255.192。按位与运算我们来看大儿子的网段192.168.1.0/26是如何得到的？以大儿子的房间为例：192.168.1.0-192.168.1.63二进制表示：192.168.1.011000000.10101000.00000001.00000000192.168.1.6311000000.10101000.00000001.00111111首尾地址完全相同的是多少？11000000.10101000.00000001.00数数一共多少位？26位！那么用这个“192.168.1.0/26”就可以表示大儿子所有房间。对照房间的门牌号码“192.168.1.199”，很显然属于四儿子的。一个主机192.168.1.199/26 能否和直连主机192.168.1.200/24 通信？可以的，因为都是四儿子的房间。一个主机192.168.1.199/26 能否和直连主机192.168.1.1/24 通信？ 不可以，因为一个是大儿子的房间，一个是四儿子的房间，无法直连通信！</p>
]]></content>
    
    <summary type="html">
    
      &lt;p&gt;掩码的作用是划分区域&lt;/p&gt;
&lt;p&gt;子网掩码使用与IP相同的编址格式，子网掩码为1的部分对应于IP地址的网络与子网部分，子网掩码为0的部分对应于IP地址的主机部分。将子网掩码和IP地址作”与”操作后，IP地址的主机部分将被丢弃，剩余的是网络地址和子网地址。例如，一个IP分组的目的IP地址为：10.2.2.1，若子网掩码为：255.255.255.0，与之作”与”运算得：10.2.2.0，则网络设备认为该IP地址的网络号与子网号为：10.2.2.0。&lt;/p&gt;
&lt;p&gt;内网中192.168.1.199的前三组是网络号，后一组是主机号，子网掩码就是255.255.255.0&lt;/p&gt;
&lt;p&gt;如果IP同样是192.168.1.199 那么子网掩码可以设成255.255.255.192吗，怎么理解&lt;/p&gt;
&lt;p&gt;如果在同一个局域网出现这两种掩码可以相互通讯吗&lt;br&gt;
    
    </summary>
    
      <category term="网络" scheme="http://sunhao.win/categories/%E7%BD%91%E7%BB%9C/"/>
    
    
      <category term="ip" scheme="http://sunhao.win/tags/ip/"/>
    
      <category term="子网掩码" scheme="http://sunhao.win/tags/%E5%AD%90%E7%BD%91%E6%8E%A9%E7%A0%81/"/>
    
  </entry>
  
  <entry>
    <title>内网IP与外网的关系？</title>
    <link href="http://sunhao.win/articles/netwrok-ip-kind.html"/>
    <id>http://sunhao.win/articles/netwrok-ip-kind.html</id>
    <published>2017-08-29T07:12:30.000Z</published>
    <updated>2017-08-29T07:26:43.179Z</updated>
    
    <content type="html"><![CDATA[<blockquote>
<p><a href="https://www.zhihu.com/question/43517806" target="_blank" rel="external">https://www.zhihu.com/question/43517806</a></p>
</blockquote>
<p>本人学习之中碰到余下疑惑，百度、必应都没找到很明确的答案，希望有懂得的人解答一二，谢谢。<br>1.看别人说内网IP可以随意分配，比如你的外网是个C类的，内网IP可以设A类的。   要是能这样一个C类公网的内网不就能容纳很多主机了，又有人说一个C类网络只能容纳254台主机。<br>2.现在划分子网时借的主机位能不能全0或全1。 好像现在不用在乎这，可老版的书又不让用，求解答。<br>3.申请的公网IP是一个具体的IP地址用在与公网连接的路由器上还是一个网段。</p>
<p>我猜测申请的公网是一个具体的IP，用在与公网连接的路由器上，内网随意设置（个别IP除外），然后经过路由器时由路由器转换，不知道猜的对不对。</p>
<p>诚心求解。</p>
<p>谢谢各位的回答，可能是匿名的关系消息也没个提示，看了你们的解答对这几个问题目前没有疑惑了，十分感谢，祝你们万事如意。<br>还是得多看书，后来发现书上都有。。。<br><a id="more"></a><br>问题1:</p>
<p>A类地址：</p>
<p>1.0.0.0 /8 - 126.0.0.0/8</p>
<p>127.0.0.0/8 保留给local host</p>
<p>每个A类地址 256<em>256</em>256=16777216</p>
<p>B类地址：</p>
<p>128.0.0.0/16 - 191.255.0.0/16 </p>
<p>每个B类地址 256*256= 65536</p>
<p>C类地址：</p>
<p>192.0.0.0/24 - 223.255.255.0/24 </p>
<p>每个C类地址：256，以前考虑到需要一个保留做网段地址，一个做广播地址，所以一个C类能给主机使用的是254个地址</p>
<p>但是每个类都保留一些地址做私有地址，即常说的内网地址：</p>
<p>10.0.0.0/8</p>
<p>172.16.0.0/16 - 172.31.0.0/16</p>
<p>192.168.0.0/16</p>
<p>私有地址随便使用，没有任何限制。</p>
<p>A类、B类，C类除了以上的私有地址都为公网地址，即常说得外网地址。</p>
<p>ABC类公网地址只要路由可达，即可以互相通信，不是说只有A类和A类通信，C类和C类通信。</p>
<p>企业或者个人如果使用是私有地址，则需要在Internet 网关上作地址翻译NAT，将私有地址翻译成网关的公网地址。</p>
<p>问题2:</p>
<p>随着IPv4地址的的枯竭，设备商、运营商采用了/31位的子网掩码，以前使用的是/30位的子网掩码，比如100.1.1.0/30，只有100.1.1.1，100.1.1.2 可以使用，而100.1.1.0，100.1.1.3保留为网段地址、广播地址，白白浪费了；如果采用100.1.1.0/31，则100.1.1.0，100.1.1.1都可以使用，没有任何地址浪费！</p>
<p>问题3:</p>
<p>申请的IP地址既可以是一个，也可以是多个，即一个网段的多个地址，这要看自己的需求。</p>
<p>编辑于 2016-05-29</p>
]]></content>
    
    <summary type="html">
    
      &lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://www.zhihu.com/question/43517806&quot; target=&quot;_blank&quot; rel=&quot;external&quot;&gt;https://www.zhihu.com/question/43517806&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;本人学习之中碰到余下疑惑，百度、必应都没找到很明确的答案，希望有懂得的人解答一二，谢谢。&lt;br&gt;1.看别人说内网IP可以随意分配，比如你的外网是个C类的，内网IP可以设A类的。   要是能这样一个C类公网的内网不就能容纳很多主机了，又有人说一个C类网络只能容纳254台主机。&lt;br&gt;2.现在划分子网时借的主机位能不能全0或全1。 好像现在不用在乎这，可老版的书又不让用，求解答。&lt;br&gt;3.申请的公网IP是一个具体的IP地址用在与公网连接的路由器上还是一个网段。&lt;/p&gt;
&lt;p&gt;我猜测申请的公网是一个具体的IP，用在与公网连接的路由器上，内网随意设置（个别IP除外），然后经过路由器时由路由器转换，不知道猜的对不对。&lt;/p&gt;
&lt;p&gt;诚心求解。&lt;/p&gt;
&lt;p&gt;谢谢各位的回答，可能是匿名的关系消息也没个提示，看了你们的解答对这几个问题目前没有疑惑了，十分感谢，祝你们万事如意。&lt;br&gt;还是得多看书，后来发现书上都有。。。&lt;br&gt;
    
    </summary>
    
      <category term="网络" scheme="http://sunhao.win/categories/%E7%BD%91%E7%BB%9C/"/>
    
    
      <category term="ip" scheme="http://sunhao.win/tags/ip/"/>
    
      <category term="内网" scheme="http://sunhao.win/tags/%E5%86%85%E7%BD%91/"/>
    
  </entry>
  
  <entry>
    <title>css-oocss-samcss-sem</title>
    <link href="http://sunhao.win/articles/css-oocss-samcss-sem.html"/>
    <id>http://sunhao.win/articles/css-oocss-samcss-sem.html</id>
    <published>2017-08-21T01:21:52.000Z</published>
    <updated>2017-08-23T02:58:21.518Z</updated>
    
    <content type="html"><![CDATA[<h2 id="OOCSS"><a href="#OOCSS" class="headerlink" title="OOCSS"></a>OOCSS</h2><h3 id="OOCSS-翻译过来意思是-面向对象的css"><a href="#OOCSS-翻译过来意思是-面向对象的css" class="headerlink" title="OOCSS 翻译过来意思是 面向对象的css"></a>OOCSS 翻译过来意思是 面向对象的css</h3><p>很多没有接触过面向对象，或者没有理解的朋友可能觉得oocss这个是框架。</p>
<p>其实面向对象分为  面向对象分析  面向对象编程  面向对象语言  面型对象思想 面向对象设计</p>
<p>看着挺复杂，就我的教学经验。初学只需要从思想和代码上认识就可以。</p>
<p>思想上，面向对象，是人认识客观事物的方式。是思想，就是思维方式。  和敲代码没有任何关系。</p>
<p>首先我们要区分类和对象。</p>
<p>我们把马这一种类叫  类。</p>
<p>把小红正在骑的马(客观存在，不以人的意识为转移)   这个叫实例，也就是我们的对象。</p>
<p>我们把大千世界真实存在的马，归为一类  给他们起了名字   叫马。 这是一种抽象概括的过程。</p>
<p>我们从马中找出创建我们的真实存在的马。这叫实例化。</p>
<p>简单点，我是真实存在的，但”人”这个名词是概念。所以我是对象，”人”是类。  我来源与类。</p>
<p>而我们的面向对象，就是面向的一个一个客观存在的实物。你看到的想到的是真实存在的(包括思想).比如还是我，我都能在这打字，是不是真实存在的。包括思想，你在想媳妇，这个想的动作，也是真实存在的。也是对象。</p>
<p>简单点，凡是能意思到，能感受到的都是对象。但人这个名词是我们抽象出来的，我们无从感受到它，它是一个类。</p>
<p>好吧，估计好多小伙伴脑细胞死一半了。我们再简单点。从自身的角度看世界。冥想一下。</p>
<p>我走在原始森林，看到了好多树，这些树都是真实存在的，这是你能感受到的。</p>
<p>回去你给小伙伴说，我看到了好多树， 你们这时候沟通时候，对方是没法意识到你看到的树，对它而言，这个树就是一个概念。也就是我们的类。</p>
<p>然后你继续给小伙伴说，其中在最中央有个撑天大树，很高很大。这个说的也是类。只是类的范围缩小了。</p>
<p>当小伙伴去过去，亲眼看到的时候，它客观存在，这个时候在他意识中就成了对象。</p>
<p>即必须是客观存在，能被意识到。如果意识不到，在人的角度，经过抽象就是一个类。</p>
<p>凡是抽象的都是类。凡是意识到的都是对象。</p>
<p>那梵高的话那么抽象它是类么？</p>
<p>首先来说，梵高抽象的是自己的感情，这里的抽象是他自己真实的感情，抽象的过程是对象，但他画里面的感情是被抽象过的，是一种概括的类。</p>
<p>好吧，现在脑细胞都死掉了吧。哈哈哈哈。其实我写的都是比喻，比较简单了。真的哦。不信你们可以看些教材。然后脑细胞会成负的。。。。</p>
<p>所以在这我建议大家，有个认识就可以，不影响编程。在随后漫长的人生中，细细体味。思想无法传递和跨越，不需要苛求对错。</p>
<p>下面我们说说编程吧</p>
<p>传统的道家学说吸收了阴阳五行。</p>
<p>阴阳化万物，天为阳，地为阴。一动，一静。衍生万物。</p>
<p>这和我们编程有啥关系呢。。</p>
<p>其实面相对象只是阴阳学说的一种表象。我们从头说起吧。</p>
<p>在编程之初，代码是比较简单和可以控制的。就是按顺序一两个人写出来。</p>
<p>但是随着硬件性能的成倍提高，用户对程序的要求也不断提高，对时间，性能，稳定也更苛刻。</p>
<p>传统面向过程(这个是目前大部分小白的写法，就是想到啥写啥，按顺序把需求完成)</p>
<p>无法预估项目，不适合多人开发，时间无法把控。而且维护困难，因为你是一个人从头到尾写的。</p>
<p>上面错了，下面业务可能全乱了。牵一发而动全身。哈哈哈哈哈</p>
<p>想让别人帮忙吧。但你业务都是从上到下写的。只好和小伙伴协商，分开写，导致代码臃肿，突然你写到一半。发现少约定个参数，然后你小伙伴也写了一半。然后就扯淡了。</p>
<p>所以我们要用面向对象编程来解决。</p>
<p>面向对象把业务拆分开。面对的不再是过程，而是对象。</p>
<p>而对象又包含，静态的属性和 动态的方法。</p>
<p>通过  动  和静  演化万众功能。</p>
<p>通过拆分动静，  静的重复利用，动的相同部分也可以利用，</p>
<p>oocss  准确的说  是一种编辑css的思想。又因为没有语法限制，所以片面点讲就是一种书写规范。</p>
<p>很高兴 你能闯过刀山火海来看到这里<br>我们继续</p>
<p>其实oocss是一种思想，所以每个人理解都是由一种偏差，所以为了学习，我们还是要有个规范<br>引用wiki的话</p>
<p>OOCSS的重点是将页面元素作为对象，给所有对象设置类名，将类作为样式表中的单个实体处理，并从它中获取。</p>
<p>在这篇文章中，我将通过介绍面向对象的css的概念以及如何帮助提高web页面的性能和可维护性来处理这一经常被忽略的领域。</p>
<p>与任何基于对象的编码方法一样，OOCSS的目的是鼓励代码重用，最终更快捷、更高效的样式表更容易添加和维护。<br>Object-oriented CSS (OOCSS) 是 CSS的扩展和升级  </p>
<p>引用OOCSS之父Nicole Sullivan话来说， 面向对象的CSS有两个原则：</p>
<p>独立的结构和样式</p>
<p>视觉性的特征具有可重复性，比如红色方块连衣裙，那么红色方块这种装饰性的东西，是不是也可以用到红色方块墙体和衣服呢？</p>
<p>而结构往往具有独立和不可重复性。</p>
<p>独立的容器和内容</p>
<p>所谓容器 就是 最外层的盒子    容器本身不包含任何样式   他的样式由内容显示</p>
<p>这样内容的样式具有可以</p>
<p>OOCSS的两大原则 </p>
<p>分离结构与皮肤 </p>
<p>这意味着将重复的视觉功能(如背景和边框样式)定义为单独的“皮肤”，您可以与不同的对象进行混合和匹配，以实现大量的视觉多样性，但没有太多代码。请参阅模块对象及其皮肤。 分离结构和皮肤也意味着使用类来命名对象及其组件，而不是仅仅依赖于html的语义。例如，媒体对象被命名为类=“媒体”，其组件以类=“img”(用于图像/视频组件)和类=“bd”(为body/text组件)命名。 通过引用样式表中的这些类(表示，而不是直接样式化元素)，您的html可以灵活。例如，如果在未来几年中，一个新的媒体元素将会被起飞(例如&lt;；svg&gt;；)，它可以集成到html中，而不必触摸css。 分离容器和内容 从本质上讲，这意味着“很少使用位置依赖样式”。无论你把物体放在哪里，物体都应该是一样的。因此，不要使用特定的<br>进行样式化。myObject{.}，创建并应用一个类，该类描述了有关<br>的问题，如<br>。 这给了您保证：(1)所有的unclassed<br>s都会看起来相同；(2)所有具有类别类(称为mixin)的元素都会看起来相同； 3)当实际需要时，不需要为该例创建一个重写样式。myObject看起来像正常的</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line"><span class="selector-id">#button</span> &#123;</div><div class="line">  <span class="attribute">width</span>: <span class="number">200px</span>;</div><div class="line">  <span class="attribute">height</span>: <span class="number">50px</span>;</div><div class="line">  <span class="attribute">padding</span>: <span class="number">10px</span>;</div><div class="line">  <span class="attribute">border</span>: solid <span class="number">1px</span> <span class="number">#ccc</span>;</div><div class="line">  <span class="attribute">background</span>: <span class="built_in">linear-gradient</span>(#ccc, #222);</div><div class="line">  <span class="attribute">box-shadow</span>: <span class="built_in">rgba</span>(0, 0, 0, .5) <span class="number">2px</span> <span class="number">2px</span> <span class="number">5px</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-id">#box</span> &#123;</div><div class="line">  <span class="attribute">width</span>: <span class="number">400px</span>;</div><div class="line">  <span class="attribute">overflow</span>: hidden;</div><div class="line">  <span class="attribute">border</span>: solid <span class="number">1px</span> <span class="number">#ccc</span>;</div><div class="line">  <span class="attribute">background</span>: <span class="built_in">linear-gradient</span>(#ccc, #222);</div><div class="line">  <span class="attribute">box-shadow</span>: <span class="built_in">rgba</span>(0, 0, 0, .5) <span class="number">2px</span> <span class="number">2px</span> <span class="number">5px</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-id">#widget</span> &#123;</div><div class="line">  <span class="attribute">width</span>: <span class="number">500px</span>;</div><div class="line">  <span class="attribute">min-height</span>: <span class="number">200px</span>;</div><div class="line">  <span class="attribute">overflow</span>: auto;</div><div class="line">  <span class="attribute">border</span>: solid <span class="number">1px</span> <span class="number">#ccc</span>;</div><div class="line">  <span class="attribute">background</span>: <span class="built_in">linear-gradient</span>(#ccc, #222);</div><div class="line">  <span class="attribute">box-shadow</span>: <span class="built_in">rgba</span>(0, 0, 0, .5) <span class="number">2px</span> <span class="number">2px</span> <span class="number">5px</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>上面的三个元素都有各自独有的样式，并且它们被应用于非可重用的ID选择器中，以定义样式。但他们也有很多风格的共同点。常见的样式可能存在于品牌目的或设计的一致性上。</p>
<p>有了一点规划和思考，我们就可以抽象出常见的样式，这样css就会变成这样：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="selector-class">.button</span> &#123;</div><div class="line">  <span class="attribute">width</span>: <span class="number">200px</span>;</div><div class="line">  <span class="attribute">height</span>: <span class="number">50px</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-class">.box</span> &#123;</div><div class="line">  <span class="attribute">width</span>: <span class="number">400px</span>;</div><div class="line">  <span class="attribute">overflow</span>: hidden;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-class">.widget</span> &#123;</div><div class="line">  <span class="attribute">width</span>: <span class="number">500px</span>;</div><div class="line">  <span class="attribute">min-height</span>: <span class="number">200px</span>;</div><div class="line">  <span class="attribute">overflow</span>: auto;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-class">.skin</span> &#123;</div><div class="line">  <span class="attribute">border</span>: solid <span class="number">1px</span> <span class="number">#ccc</span>;</div><div class="line">  <span class="attribute">background</span>: <span class="built_in">linear-gradient</span>(#ccc, #222);</div><div class="line">  <span class="attribute">box-shadow</span>: <span class="built_in">rgba</span>(0, 0, 0, .5) <span class="number">2px</span> <span class="number">2px</span> <span class="number">5px</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>现在所有的元素都是使用类，通常的样式被组合成一个可重用的“皮肤”，而没有必要重复。我们只需要将“皮肤”类应用到所有元素中，结果将与第一个示例所生成的结果相同，除了代码少和用于进一步重用的possiblity之外。<br>SEPARATION OF CONTAINERS AND CONTENT LINK<br>在OOCSS GitHub页面上描述的第二个原则是将容器与其内容分离。为了说明为什么这是重要的，请采取以下css：<br><figure class="highlight css"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="selector-id">#sidebar</span> <span class="selector-tag">h3</span> &#123;</div><div class="line">  <span class="attribute">font-family</span>: Arial, Helvetica, sans-serif;</div><div class="line">  <span class="attribute">font-size</span>: .<span class="number">8em</span>;</div><div class="line">  <span class="attribute">line-height</span>: <span class="number">1</span>;</div><div class="line">  <span class="attribute">color</span>: <span class="number">#777</span>;</div><div class="line">  <span class="attribute">text-shadow</span>: <span class="built_in">rgba</span>(0, 0, 0, .3) <span class="number">3px</span> <span class="number">3px</span> <span class="number">6px</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>这些样式将应用于任何#sidebar h3标题。但是，如果我们想将完全相同的样式应用到在footer h3标题，除了不同字体大小和修改后的文本阴影之外，还会怎样呢？<br><figure class="highlight css"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="selector-id">#sidebar</span> <span class="selector-tag">h3</span>, <span class="selector-id">#footer</span> <span class="selector-tag">h3</span> &#123;</div><div class="line">  <span class="attribute">font-family</span>: Arial, Helvetica, sans-serif;</div><div class="line">  <span class="attribute">font-size</span>: <span class="number">2em</span>;</div><div class="line">  <span class="attribute">line-height</span>: <span class="number">1</span>;</div><div class="line">  <span class="attribute">color</span>: <span class="number">#777</span>;</div><div class="line">  <span class="attribute">text-shadow</span>: <span class="built_in">rgba</span>(0, 0, 0, .3) <span class="number">3px</span> <span class="number">3px</span> <span class="number">6px</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-id">#footer</span> <span class="selector-tag">h3</span> &#123;</div><div class="line">  <span class="attribute">font-size</span>: <span class="number">1.5em</span>;</div><div class="line">  <span class="attribute">text-shadow</span>: <span class="built_in">rgba</span>(0, 0, 0, .3) <span class="number">2px</span> <span class="number">2px</span> <span class="number">4px</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>或者我们可能会有更糟的事情：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="selector-id">#sidebar</span> <span class="selector-tag">h3</span> &#123;</div><div class="line">  <span class="attribute">font-family</span>: Arial, Helvetica, sans-serif;</div><div class="line">  <span class="attribute">font-size</span>: <span class="number">2em</span>;</div><div class="line">  <span class="attribute">line-height</span>: <span class="number">1</span>;</div><div class="line">  <span class="attribute">color</span>: <span class="number">#777</span>;</div><div class="line">  <span class="attribute">text-shadow</span>: <span class="built_in">rgba</span>(0, 0, 0, .3) <span class="number">3px</span> <span class="number">3px</span> <span class="number">6px</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="comment">/* other styles here.... */</span></div><div class="line"></div><div class="line"><span class="selector-id">#footer</span> <span class="selector-tag">h3</span> &#123;</div><div class="line">  <span class="attribute">font-family</span>: Arial, Helvetica, sans-serif;</div><div class="line">  <span class="attribute">font-size</span>: <span class="number">1.5em</span>;</div><div class="line">  <span class="attribute">line-height</span>: <span class="number">1</span>;</div><div class="line">  <span class="attribute">color</span>: <span class="number">#777</span>;</div><div class="line">  <span class="attribute">text-shadow</span>: <span class="built_in">rgba</span>(0, 0, 0, .3) <span class="number">2px</span> <span class="number">2px</span> <span class="number">4px</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>现在，我们不必要地复制样式，可能不会意识到它(或者根本不关心)。</p>
<p>通过OOCSS，我们被鼓励对不同元素中常见的内容进行更多的思考，然后将这些常见特性分离到模块或对象中，这些模块或对象可以在任何地方重用。 </p>
<p>在上述示例中使用子代选择器声明的样式是不可重用的，因为它们依赖于特定的容器(在本例中是#sidebar或#footer)。 当我们使用OOCSS的基于类的模块构建时，我们确保我们的样式不依赖于任何包含元素。这意味着，无论结构上下文如何，它们都可以重用在文档的任何地方。</p>
<p>一个真实世界的例子</p>
<p>为了进一步说明如何使用OOCSS，我将使用类似于我在网站最近的重新设计中所做的事情。在对站点上的内部标头元素进行编码后，我意识到页眉内的基本结构样式可以在页面上的其他元素上重用。 因此，这里有一些我开始设计标题时所拥有的线条：</p>
<p>因此，这里有一些我开始设计标题时所拥有的线条：</p>
<p>.header-inside {<br>  width: 980px;<br>  height: 260px;<br>  padding: 20px;<br>  margin: 0 auto;<br>  position: relative;<br>  overflow: hidden;<br>}</p>
<p>这里列出的几种样式是唯一的。.header-inside元素。但其余部分可以形成一个可以重用的模块。因此，我可以将结构样式抽象成自己的可重用类。这是结</p>
<p>.globalwidth {<br>  width: 980px;<br>  margin: 0 auto;<br>  position: relative;<br>  padding-left: 20px;<br>  padding-right: 20px;<br>  overflow: hidden;<br>}</p>
<p>.header-inside {<br>  padding-top: 20px;<br>  padding-bottom: 20px;<br>  height: 260px;<br>}</p>
<p>A fixed width<br>Centering using margin: auto<br>Relative positioning to create a positioning context for child elements<br>Left and right padding of 20px<br>Overflow set to “hidden” for clearfixing</p>
<p>固定宽度 用边缘定位：自动 相对定位为子元素创建定位上下文 左的左、右填充 溢出设置为“隐藏”为clearfixing。<br>现在，我们可以在任何需要相同特性的元素上使用这些样式，只需将该类添加到所需的元素中-而无需编写单独的CSS行。 对于我的站点，我在主内容元素和内页脚元素上重用了这些结构样式。根据设计，这些样式也可以适用于可能出现在页眉和内容之间的水平导航元素，也可以适用于任何具有固定宽度的其他元素，并且需要居中在页面上。 将“globalwidth”样式添加到这些元素后，标记将看起来类似如下：</p>
<header><br>  <div class="header-inside globalwidth"><br>  </div><br></header>

<div class="main globalwidth"><br></div>

<footer><br>  <div class="footer-inside globalwidth"><br>  </div><br></footer>

<p>有些人可能会觉得这种样式抽象会使html变得更加复杂，并且违背了将标记与呈现分离的原则。 但是，抛开任何关于如何影响标记的辩论，没有人可以质疑，这种抽象现在使跟踪和修改用于构造这三个元素的常用样式变得更加容易</p>
<p>媒体对象<br>OOCSS运动的先驱之一是nicole sullivan。她创建了一个名为媒体对象的可重用模块，正如她所解释的那样，它可以保存数百行代码。</p>
<p>媒体对象是OOCSS强大的一个很好的例子，因为它可以包含任何大小的媒体元素，它的右边有内容。虽然许多适用于其内部内容的样式-甚至媒体元素本身的大小-都可能会发生变化，但是媒体对象本身也有共同的基础样式，以避免不必要的重复</p>
<ul>
<li>Separate structure and skin（分离结构和主题）减少对 HTML 结构的依赖 </li>
<li>Separate Container and content（分离容器和内容）增加样式的复用性<br>OOCSS好处 </li>
</ul>
<p>我已经提到了OOCSS的一些好处。<br>在这里，我将扩大这些。 </p>
<p>更快的网站链接</p>
<p> OOCSS的性能效益应该是相当清楚的</p>
<p> 。如果您在css中重复的样式较少，那么这将导致文件大小更小，从而更快地下载这些资源。</p>
<p>  的确，标记将更加混乱，从而创建更大的html文件。</p>
<p>  但是在许多情况下，标记性能的损失量将大大超过样式表性能中的增益量。</p>
<p>   另一个记住的概念是，OOCSS wiki指的是性能赠品。这指的是，每当您在css中重用某些东西时，基本上都会创建一个新的样式元素，这些元素都是CSS代码的零行。对于大型的高流量项目，这些“免费”可能是一个关键的业绩增益。 </p>
<p>   可维护的STYLESHEETS链接 使用OOCSS，而不是一个不断增长的样式表，充满了特定的战争，您将有一套易于维护的模块，在这些模块中，自然级联扮演了重要角色。 当对现有站点进行添加时，您不会在样式表的底部添加新样式，而不必考虑以前所出现的内容。相反，您将重用现有样式，并根据现有规则集扩展样式。 使用这种forethought，在编写很少的css时创建整个页面是可能的。任何现有的css模块都可以作为所有新页面的基础，并且任何新的css都是最小的。在某些情况下，您甚至可以创建一个新的完全样式的页面，而不编码一个单行的css。 这些可维护性的好处也扩展到样式表的健壮性。</p>
<p>   由于样式是模块化的，在新开发人员开始使用样式表时，基于OOCSS构建的页面可能会更少崩溃。 值得注意的要点 OOCSS在社区里引起了大量的讨论，引起了一些争议。在这里，我会试着消除几个常见的误解。 您仍然可以使用ids链接。 如果您决定以一种OOCSS方式工作，那么您的样式将主要基于css类，而您不会使用id选择器来设计元素。 因此，许多人错误地声称，OOCSS鼓励完全放弃使用IDs。但这并不是真的。 避免IDs的规则更具体地说，在选择器中不使用IDs。因此，使用OOCSS原则(从而避免使用id选择器的样式)是完全可以接受的，同时使用IDs中的使用用于javascript钩子和片段标识符。 当然，您可能有一个状态，您已经将一个id应用到一个元素，您知道该元素是页面中唯一的。因此，您可以通过避免向该元素添加类来保存几个字节，并使用选择器选择器来创建它。但即使在这种情况下，依赖于类也更安全，以确保您在将来不会遇到特定的问题。 处理小项目链接 对于较小的站点和应用程序，您可以肯定的是，OOCSS将是多余的。所以，不要把这篇文章作为OOCSS的宣传，在任何情况下都会有所不同，这取决于项目的情况。 尽管如此，我认为这是一个好主意，至少在你的项目中开始考虑OOCSS。一旦你得到了它的窍门，我相信你会发现在更大的项目上工作变得更容易，而这些项目的好处会更显著和更相关。 执行链接的一些指导方针 开始和OOCSS一起工作可能需要时间。我还在研究它，所以我不声称在这方面有所有的答案和经验。 但是这里有一些你可能想要开始做的事情，以帮助你进入一种长期的思维方式： 避免派生选择器(即不使用)。侧栏h3 避免IDs作为样式挂钩 避免将类附加到样式表中的元素(即不做div.header或h1.title)。 除了在一些罕见的情况下，避免使用！重要 使用林特来检查你的css(并知道它有选择和方法去处理它的疯狂) 使用css网格 显然有些时候，这些规则会被打破，但总的来说，这些规则是开发的好习惯，</p>
<p>   并且会导致样式表变得更小，更易于维护。 跟随nicole sullivan的工作链接 如果你想继续学习OOCSS，这个行业中最重要的人是妮可沙利文。 除了在她的博客上定期发布张贴文章外，妮可还与随行的幻灯片做了一系列的介绍。下面是一些您可能想要检查的内容： 面向对象的css(Slideshow) 高性能网站：nicole sullivan(视频) 我们最好的做法是杀了我们(Slideshow) css膨胀(Slideshow) 结论链路 许多人害怕OOCSS的意识形态，因为它似乎违背了我们所学到的许多所谓的“最佳实践”。但是一旦了解使用OOCSS的长期好处，我相信很多开发人员都会成为转换者。 总的来说，我认为OOCSS在css开发方面有着光明的未来，这是一个概念，所有开发人员都应该开始融入他们的项目-至少在某种程度上-帮助创建更快的网页，更有效，更容易维护。<br><a id="more"></a></p>
<p>一个css对象由四个部分组成： </p>
<p>html，它可以是一个或多个Dom节点，<br>关于这些节点的样式的css声明，所有这些节点都以包装器节点的类名开始。<br>组件，如用于显示所需的背景图像和精灵，<br>以及 与对象关联的javascript行为、侦听器或方法。 </p>
<p>这可能会令人困惑，因为每个css类都不一定是一个对象，但它可以是包装类的属性。</p>
<div class="mod"><br>        <div class="inner"><br>                <div class="hd">Block Head</div><br>                <div class="bd">Block Body</div><br>                <div class="ft">Block Foot</div><br>        </div><br></div>

<p>该对象是一个模块，由类mod表示。它包含四个属性节点(不能独立于模块独立运行，包括两个需要的区域，内部和正文，两个可选区域，头部和脚)。</p>
<p>OOCSS的性能效益有两方面： 对css代码进行重重用，因此需要使用更少的css代码，这意味着： 较小的文件，因此更快的传输 在网站的大多数页面中需要的css代码的百分比更大，可能会被重用，并且可能被浏览器缓存。 </p>
<p>在较小的程度上，浏览器部分的repaints和布局计算较少。 在一个页面上，更多的css规则被重用，渲染引擎花费的时间越少计算“计算值”</p>
<p>基本上，一个css“对象”是一个重复的视觉模式，可以抽象成一个独立的html、css和可能的javascript   的片段。然后，该对象可以在整个站点上重用。 例如，在OOCSS框架中，媒体对象描述包含固定大小媒体元素(如图像或视频)以及其他可变大小内容(例如文本)的内容块。另一个示例是模块对象，该对象描述一个具有必需的主体区域和可选页眉和页脚区域的通用内容块。</p>
<p>作为架构师，您应该编写结构对象；设置圆角框的创建方式，将所有的显示参数设置为角点或其他特性，并处理浏览器差异。新手为这些模块编写皮肤(边框、颜色、背景图片等)。 我使用面向对象方法构建了大型站点(页面的1000s，数百万访问者)。它的规模很好，当正确做好时，它意味着一个新手正在工作的各个组件都是相对可预测的。代码审查很容易，因为对于可接受的扩展对象的方法，有明确的规则。这种反馈使新开发人员能够快速地生产。 我在FullSIX(法国的一个网络营销机构)管理了一支前端开发人员团队，他们是我曾经共事过的最有才华的人之一。在某种程度上，我们的成功意味着，我们的工作比我们所能处理的多得多。</p>
<p>聘请前端专家是非常困难的(没有学校的这些东西！)<br>因此，我开始了一个内部实习项目，那些对探索代码感兴趣的设计师(但几乎没有以前的经验)可以成为我们团队的初级成员一个月的工作。</p>
<p> 第一周：他们学到了语义，并从现有的css中构建了html。学习构建新页面，无需编写更多的css、html语法、多个类、验证、语义、介绍代码审查等。<br> 第二周：他们在一周内建立简单的内容对象(标题、列表等)。学习css语法，如何扩展对象、颜色、%大小的文本等等。<br> 第三周：他们正在建造块皮。边界，颜色，背景图像，基本定位，精灵。他们与一位令人惊叹的高级开发人员合作，回答了一大堆问题，并帮助他们扩大学习曲线。他也碰巧是一个非常有天赋的代码审查员。<br> 第四周：他们是我团队中富有生产力的成员，他们的皮肤是生产准备的。 他们的代码是在客户端网站上运行的。它和高级开发人员写的一样好，也许更好，因为他们没有必要去学习坏习惯。*)</p>
<p>开始：我如何处理这些文件？ 三个文件，libraries.css(重置和字体从Yui)，grids.css和template.css已经准备好，其他的仍然非常不稳定。 通过下载按钮下载整个项目 打开template.html并将其保存为一个新文件。 通过扩展这些对象来调整列的数量和宽度。即使您有不同的列的页面，您只需要一个模板，因为这些列都是对象，类似于其他任何东西。您可以将它们视为可选区域，您可能有0-n左列。有关更多信息，请参见模板文档。 使用网格将任何内容区域拆分为小块。请参阅网格文档获取更多信息。 添加内容。提示：这也应该是oo。 复制和粘贴模块和聊天泡泡，在那里添加内容 基于“mod_skins.css”构建新的模块样式 如何将此部署在一个现场站点上？ 请记住，css仍然在发展，我可能会根据我收到的反馈来改变事情。 我已经将css文件拆分成网格和模板等模块。在实际站点上，您应该删除不必要的评论和减少http请求，或者站点将是超级慢。这意味着您需要将css文件合并到一个更大的文件中。我使用嵌套注释，以保持css的组织。最后，运行一个css minifier作为push/部署过程的一部分，以删除杂散注释。</p>
<p>OOCSS的主要原则<br>分离结构和皮肤<br>这意味着将重复的视觉特性（如背景和边框样式）定义为单独的“皮肤”，您可以与各种对象混合和匹配，以获得大量的视觉变化，而无需太多代码。看到模块对象和它的皮。<br>分离结构和皮肤也可以使用类的命名你的对象和组件，而不是仅仅依靠HTML语义。例如，媒体对象命名为class=“media”，其成分为class=“img”（对image/video组件）和class=“BD”（body/text组件）。<br>在你的样式表引用这些类（说的，而不是直接造型<img>元素），HTML可以灵活。例如，如果一个新的媒体元素要在未来几年内（如&lt;&lt; SVG &gt;），它可以被集成到HTML而不必接触CSS。</p>
<p>Separating structure and skin can also mean using classes to name your objects and their components, rather than relying solely on the semantics of HTML. For example, the media object is named with class=”media”, and its components are named with class=”img” (for the image/video component) and class=”bd” (for the body/text component).</p>
<p>By referencing these classes in your stylesheets (say, rather than directly styling the <img> element), your HTML can be flexible. For instance, if a new media element were to take off in the next few years (e.g. <svg>), it could be integrated into the HTML without having to touch the CSS.</svg></p>
<p>独立的容器和内容<br>从本质上讲，这意味着“很少使用位置相关的风格”。一个对象应该看起来一样，不管你把它放在哪里了。所以造型特定</p><h2>，MyObject H2 {…}，创建和应用类的描述问题的<h2>，像＜H2 class=“类别”&gt;。<br>这给你的保证：（1）所有未归类的<h2>的看起来都是相同的；（2）与类的所有元素（称为一个mixin）看起来都是相同的；3）你不需要的情况下创建一个重写的风格时，你真的想要的MyObject H2。像正常<h2>。<p></p>
<p>Essentially, this means “rarely use location-dependent styles”. An object should look the same no matter where you put it. So instead of styling a specific </p><h2> with .myObject h2 {…}, create and apply a class that describes the <h2> in question, like <h2 class="category">.<p></p>
<p>This gives you the assurance that: (1) all unclassed </p><h2>s will look the same; (2) all elements with the category class (called a mixin) will look the same; and 3) you won’t need to create an override style for the case when you actually do want .myObject h2 to look like the normal <h2>.<p></p>
</h2></h2></h2></h2></h2></h2></h2></h2></h2>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;OOCSS&quot;&gt;&lt;a href=&quot;#OOCSS&quot; class=&quot;headerlink&quot; title=&quot;OOCSS&quot;&gt;&lt;/a&gt;OOCSS&lt;/h2&gt;&lt;h3 id=&quot;OOCSS-翻译过来意思是-面向对象的css&quot;&gt;&lt;a href=&quot;#OOCSS-翻译过来意思是-面向对象的css&quot; class=&quot;headerlink&quot; title=&quot;OOCSS 翻译过来意思是 面向对象的css&quot;&gt;&lt;/a&gt;OOCSS 翻译过来意思是 面向对象的css&lt;/h3&gt;&lt;p&gt;很多没有接触过面向对象，或者没有理解的朋友可能觉得oocss这个是框架。&lt;/p&gt;
&lt;p&gt;其实面向对象分为  面向对象分析  面向对象编程  面向对象语言  面型对象思想 面向对象设计&lt;/p&gt;
&lt;p&gt;看着挺复杂，就我的教学经验。初学只需要从思想和代码上认识就可以。&lt;/p&gt;
&lt;p&gt;思想上，面向对象，是人认识客观事物的方式。是思想，就是思维方式。  和敲代码没有任何关系。&lt;/p&gt;
&lt;p&gt;首先我们要区分类和对象。&lt;/p&gt;
&lt;p&gt;我们把马这一种类叫  类。&lt;/p&gt;
&lt;p&gt;把小红正在骑的马(客观存在，不以人的意识为转移)   这个叫实例，也就是我们的对象。&lt;/p&gt;
&lt;p&gt;我们把大千世界真实存在的马，归为一类  给他们起了名字   叫马。 这是一种抽象概括的过程。&lt;/p&gt;
&lt;p&gt;我们从马中找出创建我们的真实存在的马。这叫实例化。&lt;/p&gt;
&lt;p&gt;简单点，我是真实存在的，但”人”这个名词是概念。所以我是对象，”人”是类。  我来源与类。&lt;/p&gt;
&lt;p&gt;而我们的面向对象，就是面向的一个一个客观存在的实物。你看到的想到的是真实存在的(包括思想).比如还是我，我都能在这打字，是不是真实存在的。包括思想，你在想媳妇，这个想的动作，也是真实存在的。也是对象。&lt;/p&gt;
&lt;p&gt;简单点，凡是能意思到，能感受到的都是对象。但人这个名词是我们抽象出来的，我们无从感受到它，它是一个类。&lt;/p&gt;
&lt;p&gt;好吧，估计好多小伙伴脑细胞死一半了。我们再简单点。从自身的角度看世界。冥想一下。&lt;/p&gt;
&lt;p&gt;我走在原始森林，看到了好多树，这些树都是真实存在的，这是你能感受到的。&lt;/p&gt;
&lt;p&gt;回去你给小伙伴说，我看到了好多树， 你们这时候沟通时候，对方是没法意识到你看到的树，对它而言，这个树就是一个概念。也就是我们的类。&lt;/p&gt;
&lt;p&gt;然后你继续给小伙伴说，其中在最中央有个撑天大树，很高很大。这个说的也是类。只是类的范围缩小了。&lt;/p&gt;
&lt;p&gt;当小伙伴去过去，亲眼看到的时候，它客观存在，这个时候在他意识中就成了对象。&lt;/p&gt;
&lt;p&gt;即必须是客观存在，能被意识到。如果意识不到，在人的角度，经过抽象就是一个类。&lt;/p&gt;
&lt;p&gt;凡是抽象的都是类。凡是意识到的都是对象。&lt;/p&gt;
&lt;p&gt;那梵高的话那么抽象它是类么？&lt;/p&gt;
&lt;p&gt;首先来说，梵高抽象的是自己的感情，这里的抽象是他自己真实的感情，抽象的过程是对象，但他画里面的感情是被抽象过的，是一种概括的类。&lt;/p&gt;
&lt;p&gt;好吧，现在脑细胞都死掉了吧。哈哈哈哈。其实我写的都是比喻，比较简单了。真的哦。不信你们可以看些教材。然后脑细胞会成负的。。。。&lt;/p&gt;
&lt;p&gt;所以在这我建议大家，有个认识就可以，不影响编程。在随后漫长的人生中，细细体味。思想无法传递和跨越，不需要苛求对错。&lt;/p&gt;
&lt;p&gt;下面我们说说编程吧&lt;/p&gt;
&lt;p&gt;传统的道家学说吸收了阴阳五行。&lt;/p&gt;
&lt;p&gt;阴阳化万物，天为阳，地为阴。一动，一静。衍生万物。&lt;/p&gt;
&lt;p&gt;这和我们编程有啥关系呢。。&lt;/p&gt;
&lt;p&gt;其实面相对象只是阴阳学说的一种表象。我们从头说起吧。&lt;/p&gt;
&lt;p&gt;在编程之初，代码是比较简单和可以控制的。就是按顺序一两个人写出来。&lt;/p&gt;
&lt;p&gt;但是随着硬件性能的成倍提高，用户对程序的要求也不断提高，对时间，性能，稳定也更苛刻。&lt;/p&gt;
&lt;p&gt;传统面向过程(这个是目前大部分小白的写法，就是想到啥写啥，按顺序把需求完成)&lt;/p&gt;
&lt;p&gt;无法预估项目，不适合多人开发，时间无法把控。而且维护困难，因为你是一个人从头到尾写的。&lt;/p&gt;
&lt;p&gt;上面错了，下面业务可能全乱了。牵一发而动全身。哈哈哈哈哈&lt;/p&gt;
&lt;p&gt;想让别人帮忙吧。但你业务都是从上到下写的。只好和小伙伴协商，分开写，导致代码臃肿，突然你写到一半。发现少约定个参数，然后你小伙伴也写了一半。然后就扯淡了。&lt;/p&gt;
&lt;p&gt;所以我们要用面向对象编程来解决。&lt;/p&gt;
&lt;p&gt;面向对象把业务拆分开。面对的不再是过程，而是对象。&lt;/p&gt;
&lt;p&gt;而对象又包含，静态的属性和 动态的方法。&lt;/p&gt;
&lt;p&gt;通过  动  和静  演化万众功能。&lt;/p&gt;
&lt;p&gt;通过拆分动静，  静的重复利用，动的相同部分也可以利用，&lt;/p&gt;
&lt;p&gt;oocss  准确的说  是一种编辑css的思想。又因为没有语法限制，所以片面点讲就是一种书写规范。&lt;/p&gt;
&lt;p&gt;很高兴 你能闯过刀山火海来看到这里&lt;br&gt;我们继续&lt;/p&gt;
&lt;p&gt;其实oocss是一种思想，所以每个人理解都是由一种偏差，所以为了学习，我们还是要有个规范&lt;br&gt;引用wiki的话&lt;/p&gt;
&lt;p&gt;OOCSS的重点是将页面元素作为对象，给所有对象设置类名，将类作为样式表中的单个实体处理，并从它中获取。&lt;/p&gt;
&lt;p&gt;在这篇文章中，我将通过介绍面向对象的css的概念以及如何帮助提高web页面的性能和可维护性来处理这一经常被忽略的领域。&lt;/p&gt;
&lt;p&gt;与任何基于对象的编码方法一样，OOCSS的目的是鼓励代码重用，最终更快捷、更高效的样式表更容易添加和维护。&lt;br&gt;Object-oriented CSS (OOCSS) 是 CSS的扩展和升级  &lt;/p&gt;
&lt;p&gt;引用OOCSS之父Nicole Sullivan话来说， 面向对象的CSS有两个原则：&lt;/p&gt;
&lt;p&gt;独立的结构和样式&lt;/p&gt;
&lt;p&gt;视觉性的特征具有可重复性，比如红色方块连衣裙，那么红色方块这种装饰性的东西，是不是也可以用到红色方块墙体和衣服呢？&lt;/p&gt;
&lt;p&gt;而结构往往具有独立和不可重复性。&lt;/p&gt;
&lt;p&gt;独立的容器和内容&lt;/p&gt;
&lt;p&gt;所谓容器 就是 最外层的盒子    容器本身不包含任何样式   他的样式由内容显示&lt;/p&gt;
&lt;p&gt;这样内容的样式具有可以&lt;/p&gt;
&lt;p&gt;OOCSS的两大原则 &lt;/p&gt;
&lt;p&gt;分离结构与皮肤 &lt;/p&gt;
&lt;p&gt;这意味着将重复的视觉功能(如背景和边框样式)定义为单独的“皮肤”，您可以与不同的对象进行混合和匹配，以实现大量的视觉多样性，但没有太多代码。请参阅模块对象及其皮肤。 分离结构和皮肤也意味着使用类来命名对象及其组件，而不是仅仅依赖于html的语义。例如，媒体对象被命名为类=“媒体”，其组件以类=“img”(用于图像/视频组件)和类=“bd”(为body/text组件)命名。 通过引用样式表中的这些类(表示，而不是直接样式化元素)，您的html可以灵活。例如，如果在未来几年中，一个新的媒体元素将会被起飞(例如&amp;lt;；svg&amp;gt;；)，它可以集成到html中，而不必触摸css。 分离容器和内容 从本质上讲，这意味着“很少使用位置依赖样式”。无论你把物体放在哪里，物体都应该是一样的。因此，不要使用特定的&lt;br&gt;进行样式化。myObject{.}，创建并应用一个类，该类描述了有关&lt;br&gt;的问题，如&lt;br&gt;。 这给了您保证：(1)所有的unclassed&lt;br&gt;s都会看起来相同；(2)所有具有类别类(称为mixin)的元素都会看起来相同； 3)当实际需要时，不需要为该例创建一个重写样式。myObject看起来像正常的&lt;/p&gt;
&lt;figure class=&quot;highlight css&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;18&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;19&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;20&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;21&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;22&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;23&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;24&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;25&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-id&quot;&gt;#button&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;200px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;50px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;padding&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;10px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;border&lt;/span&gt;: solid &lt;span class=&quot;number&quot;&gt;1px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;#ccc&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;background&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;linear-gradient&lt;/span&gt;(#ccc, #222);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;box-shadow&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;rgba&lt;/span&gt;(0, 0, 0, .5) &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;5px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-id&quot;&gt;#box&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;400px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;overflow&lt;/span&gt;: hidden;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;border&lt;/span&gt;: solid &lt;span class=&quot;number&quot;&gt;1px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;#ccc&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;background&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;linear-gradient&lt;/span&gt;(#ccc, #222);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;box-shadow&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;rgba&lt;/span&gt;(0, 0, 0, .5) &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;5px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-id&quot;&gt;#widget&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;500px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;min-height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;200px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;overflow&lt;/span&gt;: auto;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;border&lt;/span&gt;: solid &lt;span class=&quot;number&quot;&gt;1px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;#ccc&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;background&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;linear-gradient&lt;/span&gt;(#ccc, #222);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;box-shadow&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;rgba&lt;/span&gt;(0, 0, 0, .5) &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;5px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;上面的三个元素都有各自独有的样式，并且它们被应用于非可重用的ID选择器中，以定义样式。但他们也有很多风格的共同点。常见的样式可能存在于品牌目的或设计的一致性上。&lt;/p&gt;
&lt;p&gt;有了一点规划和思考，我们就可以抽象出常见的样式，这样css就会变成这样：&lt;/p&gt;
&lt;figure class=&quot;highlight css&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;18&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;19&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;20&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;21&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.button&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;200px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;50px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.box&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;400px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;overflow&lt;/span&gt;: hidden;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.widget&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;500px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;min-height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;200px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;overflow&lt;/span&gt;: auto;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.skin&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;border&lt;/span&gt;: solid &lt;span class=&quot;number&quot;&gt;1px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;#ccc&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;background&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;linear-gradient&lt;/span&gt;(#ccc, #222);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;box-shadow&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;rgba&lt;/span&gt;(0, 0, 0, .5) &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;5px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;现在所有的元素都是使用类，通常的样式被组合成一个可重用的“皮肤”，而没有必要重复。我们只需要将“皮肤”类应用到所有元素中，结果将与第一个示例所生成的结果相同，除了代码少和用于进一步重用的possiblity之外。&lt;br&gt;SEPARATION OF CONTAINERS AND CONTENT LINK&lt;br&gt;在OOCSS GitHub页面上描述的第二个原则是将容器与其内容分离。为了说明为什么这是重要的，请采取以下css：&lt;br&gt;&lt;figure class=&quot;highlight css&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-id&quot;&gt;#sidebar&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;h3&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;font-family&lt;/span&gt;: Arial, Helvetica, sans-serif;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;font-size&lt;/span&gt;: .&lt;span class=&quot;number&quot;&gt;8em&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;line-height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#777&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;text-shadow&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;rgba&lt;/span&gt;(0, 0, 0, .3) &lt;span class=&quot;number&quot;&gt;3px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;3px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;6px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;这些样式将应用于任何#sidebar h3标题。但是，如果我们想将完全相同的样式应用到在footer h3标题，除了不同字体大小和修改后的文本阴影之外，还会怎样呢？&lt;br&gt;&lt;figure class=&quot;highlight css&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-id&quot;&gt;#sidebar&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;h3&lt;/span&gt;, &lt;span class=&quot;selector-id&quot;&gt;#footer&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;h3&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;font-family&lt;/span&gt;: Arial, Helvetica, sans-serif;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;font-size&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;2em&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;line-height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#777&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;text-shadow&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;rgba&lt;/span&gt;(0, 0, 0, .3) &lt;span class=&quot;number&quot;&gt;3px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;3px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;6px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-id&quot;&gt;#footer&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;h3&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;font-size&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1.5em&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;text-shadow&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;rgba&lt;/span&gt;(0, 0, 0, .3) &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;4px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;或者我们可能会有更糟的事情：&lt;/p&gt;
&lt;figure class=&quot;highlight css&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-id&quot;&gt;#sidebar&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;h3&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;font-family&lt;/span&gt;: Arial, Helvetica, sans-serif;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;font-size&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;2em&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;line-height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#777&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;text-shadow&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;rgba&lt;/span&gt;(0, 0, 0, .3) &lt;span class=&quot;number&quot;&gt;3px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;3px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;6px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;/* other styles here.... */&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-id&quot;&gt;#footer&lt;/span&gt; &lt;span class=&quot;selector-tag&quot;&gt;h3&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;font-family&lt;/span&gt;: Arial, Helvetica, sans-serif;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;font-size&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1.5em&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;line-height&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#777&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;text-shadow&lt;/span&gt;: &lt;span class=&quot;built_in&quot;&gt;rgba&lt;/span&gt;(0, 0, 0, .3) &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;4px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;现在，我们不必要地复制样式，可能不会意识到它(或者根本不关心)。&lt;/p&gt;
&lt;p&gt;通过OOCSS，我们被鼓励对不同元素中常见的内容进行更多的思考，然后将这些常见特性分离到模块或对象中，这些模块或对象可以在任何地方重用。 &lt;/p&gt;
&lt;p&gt;在上述示例中使用子代选择器声明的样式是不可重用的，因为它们依赖于特定的容器(在本例中是#sidebar或#footer)。 当我们使用OOCSS的基于类的模块构建时，我们确保我们的样式不依赖于任何包含元素。这意味着，无论结构上下文如何，它们都可以重用在文档的任何地方。&lt;/p&gt;
&lt;p&gt;一个真实世界的例子&lt;/p&gt;
&lt;p&gt;为了进一步说明如何使用OOCSS，我将使用类似于我在网站最近的重新设计中所做的事情。在对站点上的内部标头元素进行编码后，我意识到页眉内的基本结构样式可以在页面上的其他元素上重用。 因此，这里有一些我开始设计标题时所拥有的线条：&lt;/p&gt;
&lt;p&gt;因此，这里有一些我开始设计标题时所拥有的线条：&lt;/p&gt;
&lt;p&gt;.header-inside {&lt;br&gt;  width: 980px;&lt;br&gt;  height: 260px;&lt;br&gt;  padding: 20px;&lt;br&gt;  margin: 0 auto;&lt;br&gt;  position: relative;&lt;br&gt;  overflow: hidden;&lt;br&gt;}&lt;/p&gt;
&lt;p&gt;这里列出的几种样式是唯一的。.header-inside元素。但其余部分可以形成一个可以重用的模块。因此，我可以将结构样式抽象成自己的可重用类。这是结&lt;/p&gt;
&lt;p&gt;.globalwidth {&lt;br&gt;  width: 980px;&lt;br&gt;  margin: 0 auto;&lt;br&gt;  position: relative;&lt;br&gt;  padding-left: 20px;&lt;br&gt;  padding-right: 20px;&lt;br&gt;  overflow: hidden;&lt;br&gt;}&lt;/p&gt;
&lt;p&gt;.header-inside {&lt;br&gt;  padding-top: 20px;&lt;br&gt;  padding-bottom: 20px;&lt;br&gt;  height: 260px;&lt;br&gt;}&lt;/p&gt;
&lt;p&gt;A fixed width&lt;br&gt;Centering using margin: auto&lt;br&gt;Relative positioning to create a positioning context for child elements&lt;br&gt;Left and right padding of 20px&lt;br&gt;Overflow set to “hidden” for clearfixing&lt;/p&gt;
&lt;p&gt;固定宽度 用边缘定位：自动 相对定位为子元素创建定位上下文 左的左、右填充 溢出设置为“隐藏”为clearfixing。&lt;br&gt;现在，我们可以在任何需要相同特性的元素上使用这些样式，只需将该类添加到所需的元素中-而无需编写单独的CSS行。 对于我的站点，我在主内容元素和内页脚元素上重用了这些结构样式。根据设计，这些样式也可以适用于可能出现在页眉和内容之间的水平导航元素，也可以适用于任何具有固定宽度的其他元素，并且需要居中在页面上。 将“globalwidth”样式添加到这些元素后，标记将看起来类似如下：&lt;/p&gt;
&lt;header&gt;&lt;br&gt;  &lt;div class=&quot;header-inside globalwidth&quot;&gt;&lt;br&gt;  &lt;/div&gt;&lt;br&gt;&lt;/header&gt;

&lt;div class=&quot;main globalwidth&quot;&gt;&lt;br&gt;&lt;/div&gt;

&lt;footer&gt;&lt;br&gt;  &lt;div class=&quot;footer-inside globalwidth&quot;&gt;&lt;br&gt;  &lt;/div&gt;&lt;br&gt;&lt;/footer&gt;

&lt;p&gt;有些人可能会觉得这种样式抽象会使html变得更加复杂，并且违背了将标记与呈现分离的原则。 但是，抛开任何关于如何影响标记的辩论，没有人可以质疑，这种抽象现在使跟踪和修改用于构造这三个元素的常用样式变得更加容易&lt;/p&gt;
&lt;p&gt;媒体对象&lt;br&gt;OOCSS运动的先驱之一是nicole sullivan。她创建了一个名为媒体对象的可重用模块，正如她所解释的那样，它可以保存数百行代码。&lt;/p&gt;
&lt;p&gt;媒体对象是OOCSS强大的一个很好的例子，因为它可以包含任何大小的媒体元素，它的右边有内容。虽然许多适用于其内部内容的样式-甚至媒体元素本身的大小-都可能会发生变化，但是媒体对象本身也有共同的基础样式，以避免不必要的重复&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Separate structure and skin（分离结构和主题）减少对 HTML 结构的依赖 &lt;/li&gt;
&lt;li&gt;Separate Container and content（分离容器和内容）增加样式的复用性&lt;br&gt;OOCSS好处 &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;我已经提到了OOCSS的一些好处。&lt;br&gt;在这里，我将扩大这些。 &lt;/p&gt;
&lt;p&gt;更快的网站链接&lt;/p&gt;
&lt;p&gt; OOCSS的性能效益应该是相当清楚的&lt;/p&gt;
&lt;p&gt; 。如果您在css中重复的样式较少，那么这将导致文件大小更小，从而更快地下载这些资源。&lt;/p&gt;
&lt;p&gt;  的确，标记将更加混乱，从而创建更大的html文件。&lt;/p&gt;
&lt;p&gt;  但是在许多情况下，标记性能的损失量将大大超过样式表性能中的增益量。&lt;/p&gt;
&lt;p&gt;   另一个记住的概念是，OOCSS wiki指的是性能赠品。这指的是，每当您在css中重用某些东西时，基本上都会创建一个新的样式元素，这些元素都是CSS代码的零行。对于大型的高流量项目，这些“免费”可能是一个关键的业绩增益。 &lt;/p&gt;
&lt;p&gt;   可维护的STYLESHEETS链接 使用OOCSS，而不是一个不断增长的样式表，充满了特定的战争，您将有一套易于维护的模块，在这些模块中，自然级联扮演了重要角色。 当对现有站点进行添加时，您不会在样式表的底部添加新样式，而不必考虑以前所出现的内容。相反，您将重用现有样式，并根据现有规则集扩展样式。 使用这种forethought，在编写很少的css时创建整个页面是可能的。任何现有的css模块都可以作为所有新页面的基础，并且任何新的css都是最小的。在某些情况下，您甚至可以创建一个新的完全样式的页面，而不编码一个单行的css。 这些可维护性的好处也扩展到样式表的健壮性。&lt;/p&gt;
&lt;p&gt;   由于样式是模块化的，在新开发人员开始使用样式表时，基于OOCSS构建的页面可能会更少崩溃。 值得注意的要点 OOCSS在社区里引起了大量的讨论，引起了一些争议。在这里，我会试着消除几个常见的误解。 您仍然可以使用ids链接。 如果您决定以一种OOCSS方式工作，那么您的样式将主要基于css类，而您不会使用id选择器来设计元素。 因此，许多人错误地声称，OOCSS鼓励完全放弃使用IDs。但这并不是真的。 避免IDs的规则更具体地说，在选择器中不使用IDs。因此，使用OOCSS原则(从而避免使用id选择器的样式)是完全可以接受的，同时使用IDs中的使用用于javascript钩子和片段标识符。 当然，您可能有一个状态，您已经将一个id应用到一个元素，您知道该元素是页面中唯一的。因此，您可以通过避免向该元素添加类来保存几个字节，并使用选择器选择器来创建它。但即使在这种情况下，依赖于类也更安全，以确保您在将来不会遇到特定的问题。 处理小项目链接 对于较小的站点和应用程序，您可以肯定的是，OOCSS将是多余的。所以，不要把这篇文章作为OOCSS的宣传，在任何情况下都会有所不同，这取决于项目的情况。 尽管如此，我认为这是一个好主意，至少在你的项目中开始考虑OOCSS。一旦你得到了它的窍门，我相信你会发现在更大的项目上工作变得更容易，而这些项目的好处会更显著和更相关。 执行链接的一些指导方针 开始和OOCSS一起工作可能需要时间。我还在研究它，所以我不声称在这方面有所有的答案和经验。 但是这里有一些你可能想要开始做的事情，以帮助你进入一种长期的思维方式： 避免派生选择器(即不使用)。侧栏h3 避免IDs作为样式挂钩 避免将类附加到样式表中的元素(即不做div.header或h1.title)。 除了在一些罕见的情况下，避免使用！重要 使用林特来检查你的css(并知道它有选择和方法去处理它的疯狂) 使用css网格 显然有些时候，这些规则会被打破，但总的来说，这些规则是开发的好习惯，&lt;/p&gt;
&lt;p&gt;   并且会导致样式表变得更小，更易于维护。 跟随nicole sullivan的工作链接 如果你想继续学习OOCSS，这个行业中最重要的人是妮可沙利文。 除了在她的博客上定期发布张贴文章外，妮可还与随行的幻灯片做了一系列的介绍。下面是一些您可能想要检查的内容： 面向对象的css(Slideshow) 高性能网站：nicole sullivan(视频) 我们最好的做法是杀了我们(Slideshow) css膨胀(Slideshow) 结论链路 许多人害怕OOCSS的意识形态，因为它似乎违背了我们所学到的许多所谓的“最佳实践”。但是一旦了解使用OOCSS的长期好处，我相信很多开发人员都会成为转换者。 总的来说，我认为OOCSS在css开发方面有着光明的未来，这是一个概念，所有开发人员都应该开始融入他们的项目-至少在某种程度上-帮助创建更快的网页，更有效，更容易维护。&lt;br&gt;
    
    </summary>
    
      <category term="css" scheme="http://sunhao.win/categories/css/"/>
    
    
      <category term="oocss" scheme="http://sunhao.win/tags/oocss/"/>
    
      <category term="samcss" scheme="http://sunhao.win/tags/samcss/"/>
    
      <category term="sem" scheme="http://sunhao.win/tags/sem/"/>
    
  </entry>
  
  <entry>
    <title>js-mobile-isroll移动端滚动插件iScroll</title>
    <link href="http://sunhao.win/articles/js-mobile-isroll.html"/>
    <id>http://sunhao.win/articles/js-mobile-isroll.html</id>
    <published>2017-08-17T07:21:05.000Z</published>
    <updated>2017-08-17T07:24:53.278Z</updated>
    
    <content type="html"><![CDATA[<p>移动端滚动插件iScroll</p>
<p>目录：</p>
<p>1iScroll的产生2iScroll的使用方法3iScroll应该如何实例化4iScroll中的参数5iScroll中的方法<br>概述：</p>
<p>大家在日常工作中最常用的插件是什么，jQurey？Lazyload？但是这些都是在PC端，但是在移动端最常用的插件莫过于iScroll了，iScroll到底是什么东西，应该怎么用？iScroll是个很强大的插件，我也只是略懂皮毛，这里我们简单的介绍一下。<br>iScroll的产生：</p>
<p>iScroll的产生完全是因为移动版webkit浏览器，例如在iPhone，Android 的移动设备上。<br>iScroll的使用方法：</p>
<p>iScroll的原理是外层有一个溢出隐藏（overflow:hidden;）的DOM，然后这个区域内的第一个DOM结构会被实例化，其包裹的内容可以纵向或者横向的滚动，所以在使用iScroll的时候，滚动元素要尽量的简单，减少DOM个数，减少嵌套，因为DOM结构越是复杂iScroll运行起来就越是吃力，有可能会造成某些节点显示不正常的情况。 所以，推荐使用的DOM结构如下：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&lt;div id=&quot;wrapper&quot;&gt;//overflow:hidden;</div><div class="line">    &lt;ul&gt;</div><div class="line">    //只有第一个DOM结构（ul）被实例化，这个DOM可以纵向或者横向的滚动，</div><div class="line">    //多出的内容会被wrapper的样式hidden。</div><div class="line">        &lt;li&gt;1&lt;/li&gt;</div><div class="line">        &lt;li&gt;2&lt;/li&gt;</div><div class="line">        &lt;li&gt;3&lt;/li&gt;</div><div class="line">    &lt;/ul&gt;</div><div class="line">&lt;/div&gt;</div></pre></td></tr></table></figure></p>
<p>注意：再次重申，只有wrapper里的第一个子元素（ul）才可以被实例化滚动，并且要结合外层的DOM（wrapper）才能实现滚动。<br>如果 wrapper中有多个ul怎么办？很简单，记住那句话，只有wrapper里的第一个子元素（ul）才可以被实例化滚动：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line">&lt;div id=&quot;wrapper&quot;&gt;//overflow:hidden;</div><div class="line">    &lt;div id=&quot;first&quot;&gt;</div><div class="line">        //只有第一个DOM结构(ul)被实例化，这个DOM可以纵向或者横向的滚动，</div><div class="line">        //多出的内容会被wrapper的样式hidden</div><div class="line">        &lt;ul&gt;</div><div class="line">            &lt;li&gt;1&lt;/li&gt;</div><div class="line">            &lt;li&gt;2&lt;/li&gt;</div><div class="line">            &lt;li&gt;3&lt;/li&gt;</div><div class="line">        &lt;/ul&gt;</div><div class="line">        &lt;ul&gt;</div><div class="line">            &lt;li&gt;4&lt;/li&gt;</div><div class="line">            &lt;li&gt;5&lt;/li&gt;</div><div class="line">            &lt;li&gt;6&lt;/li&gt;</div><div class="line">        &lt;/ul&gt;</div><div class="line">    &lt;/div&gt;</div><div class="line">&lt;/div&gt;</div></pre></td></tr></table></figure></p>
<p>看到了吧，只有first会被实例化。 注意：这里第一个DOM结构的ID（first）可以不写，我只是为了方便大家识别才写了个ID，但是最外层的ID（wrapper）一定要写，因为在JS实例化的时候需要填写这个ID：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">var myScroll = new iScroll(&quot;wrapper&quot;);</div></pre></td></tr></table></figure></p>
<p>iScroll应该如何实例化：</p>
<p>既然说道了实例化，我们应该在什么时候实例化？据说实例化的方法有很多，但是我没用过，我只说一种：</p>
<p>（1）在HTML（uw3c.html）页面底部（body之后html之前）加载iscroll.js与当前页面的uw3c.js,这样能确保HTML的DOM结构能加载出来。</p>
<p>（2）在JS插入页面DOM结构和数据之前实例化iScroll，也就是在JS的最开始实例化，因为之后可能会使用JS来插入DOM或者数据，这样以来能确保在插入数据之前iScroll已经实例化了。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div></pre></td><td class="code"><pre><div class="line">HTML://HTML结构</div><div class="line">&lt;html &gt;</div><div class="line">    &lt;body&gt;</div><div class="line">     ...code...</div><div class="line">    &lt;/body&gt;</div><div class="line">     //插入iscroll.js文件</div><div class="line">   &lt;script type=&quot;text/javascript&quot; src=&quot;js/iscroll.js&quot; &gt; &lt;/script &gt;</div><div class="line">    //插入本页面JS文件</div><div class="line">  &lt;script type=&quot;text/javascript&quot; src=&quot;js/uw3c.js&quot; &gt; &lt;/script &gt;</div><div class="line">&lt;/html&gt;</div><div class="line"> JS://JS文件内容</div><div class="line"> var myscroll;</div><div class="line"> function iscroll(data)&#123;</div><div class="line">      //实例化iScroll</div><div class="line">     myscroll=new iScroll(&quot;wrapper&quot;);</div><div class="line">     pageData(data);</div><div class="line"> &#125;</div><div class="line"> function pageData(obj)&#123;</div><div class="line">     $(&quot;body&quot;).html(obj);</div><div class="line">     myscroll.refresh();//当DOM结构发生变化的时候，需要刷新iScroll</div><div class="line"> &#125;</div><div class="line"> iscroll(&quot;&lt;div&gt;pagedata&lt;/div&gt;&quot;);</div></pre></td></tr></table></figure>
<p>iScroll中的参数：</p>
<p>在实例化iScroll的时候，可以传入两个参数，第一个参数是实例化的外层的DOM的ID，第二个参数是iScroll执行方法的对象：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">var myscroll=new iScroll(&quot;wrapper&quot;,&#123;hScrollbar:false&#125;);</div></pre></td></tr></table></figure></p>
<p>或者<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">var opts = &#123;</div><div class="line">                vScroll:false,//禁止垂直滚动</div><div class="line">                snap:true,//执行传送带效果</div><div class="line">                hScrollbar:false//隐藏水平方向上的滚动条</div><div class="line">            &#125;;</div><div class="line">var myscroll = new iScroll(&quot;wrapper&quot;,opts);</div></pre></td></tr></table></figure></p>
<p>第二个参数内容如下，这个参数会控制iScroll的效果：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">hScroll        false 禁止横向滚动 true横向滚动 默认为true</div><div class="line">vScroll        false 禁止垂直滚动 true垂直滚动 默认为true</div><div class="line">hScrollbar     false隐藏水平方向上的滚动条</div><div class="line">vScrollbar     false 隐藏垂直方向上的滚动条</div><div class="line">fadeScrollbar  false 指定在无渐隐效果时隐藏滚动条</div><div class="line">hideScrollbar  在没有用户交互时隐藏滚动条 默认为true</div><div class="line">bounce         启用或禁用边界的反弹，默认为true</div><div class="line">momentum       启用或禁用惯性，默认为true，</div><div class="line">               此参数在你想要保存资源的时候非常有用</div><div class="line">lockDirection  false取消拖动方向的锁定，</div><div class="line">               true拖动只能在一个方向上（up/down 或者left/right）</div><div class="line">iScroll中的方法：</div></pre></td></tr></table></figure></p>
<p>当然在第二个参数中，也有一些方法可以执行：</p>
<p>(1)scrollTo(x, y, time, relative)方法：传入4个参数：X轴滚动距离，Y轴滚动距离，效果时间，是否相对当前位置。所以例如：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">//在200毫秒的时间内，Y轴向上滚动100像素；</div><div class="line">uw3c.scrollTo(0, -100, 200)</div><div class="line">//在200毫秒的时间内，相对于当前位置，X轴向左滚动100像素；</div><div class="line">uw3c.scrollTo(-100, 0, 200, true)</div></pre></td></tr></table></figure></p>
<p>(2)refresh()方法：在DOM结构发生改变之后，需要刷新iScroll，否则滚动插件会实例化的不准确：</p>
<p>uw3c.refresh();//刷新iScroll</p>
<p>(3)onPosChange,有没有一个方法能返回位置的变化？你可以查询一下自己所用的iScroll中有没有onPosChange方法：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">onPosChange:function(x,y)&#123;</div><div class="line">    if(y &lt; -200)&#123;</div><div class="line">     //如果Y周向上滚动200像素，$(&quot;#uw3c&quot;)就显示，否则就隐藏。</div><div class="line">        $(&quot;#uw3c&quot;).show();</div><div class="line">    &#125;else&#123;</div><div class="line">        $(&quot;#uw3c&quot;).hide();</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>（4）onScrollEnd：滚动结束时执行的事件，如果想在滚动结束时出发摸个事件，这个方法就拍上用处了：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">//滚动结束后，执行的方法，滚动后会出现提示框alert(&quot;uw3c.com&quot;)</div><div class="line">onScrollEnd:function()&#123;</div><div class="line">    alert(&quot;uw3c.com&quot;);</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>（5）onRefresh：在DOM结构发生改变之后，需要刷新iScroll，否则滚动插件会实例化的不准确，onRefresh是刷新完iScroll会执行的方法。<br>（6）onBeforeScrollStart：开始滚动前的时间回调，默认是阻止浏览器默认行为 。<br>（7）onScrollStart：开始滚动的回调。<br>（8）onBeforeScrollMove：在内容移动前的回调。<br>（9）onScrollMove：内容移动的回调。<br>（10）onBeforeScrollEnd：在滚动结束前的回调。<br>（11）onTouchEnd：手离开屏幕后的回调。<br>（12）onDestroy：销毁实例的回调。<br><a id="more"></a></p>
]]></content>
    
    <summary type="html">
    
      &lt;p&gt;移动端滚动插件iScroll&lt;/p&gt;
&lt;p&gt;目录：&lt;/p&gt;
&lt;p&gt;1iScroll的产生2iScroll的使用方法3iScroll应该如何实例化4iScroll中的参数5iScroll中的方法&lt;br&gt;概述：&lt;/p&gt;
&lt;p&gt;大家在日常工作中最常用的插件是什么，jQurey？Lazyload？但是这些都是在PC端，但是在移动端最常用的插件莫过于iScroll了，iScroll到底是什么东西，应该怎么用？iScroll是个很强大的插件，我也只是略懂皮毛，这里我们简单的介绍一下。&lt;br&gt;iScroll的产生：&lt;/p&gt;
&lt;p&gt;iScroll的产生完全是因为移动版webkit浏览器，例如在iPhone，Android 的移动设备上。&lt;br&gt;iScroll的使用方法：&lt;/p&gt;
&lt;p&gt;iScroll的原理是外层有一个溢出隐藏（overflow:hidden;）的DOM，然后这个区域内的第一个DOM结构会被实例化，其包裹的内容可以纵向或者横向的滚动，所以在使用iScroll的时候，滚动元素要尽量的简单，减少DOM个数，减少嵌套，因为DOM结构越是复杂iScroll运行起来就越是吃力，有可能会造成某些节点显示不正常的情况。 所以，推荐使用的DOM结构如下：&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&amp;lt;div id=&amp;quot;wrapper&amp;quot;&amp;gt;//overflow:hidden;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &amp;lt;ul&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    //只有第一个DOM结构（ul）被实例化，这个DOM可以纵向或者横向的滚动，&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    //多出的内容会被wrapper的样式hidden。&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &amp;lt;li&amp;gt;1&amp;lt;/li&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &amp;lt;li&amp;gt;2&amp;lt;/li&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &amp;lt;li&amp;gt;3&amp;lt;/li&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &amp;lt;/ul&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;注意：再次重申，只有wrapper里的第一个子元素（ul）才可以被实例化滚动，并且要结合外层的DOM（wrapper）才能实现滚动。&lt;br&gt;如果 wrapper中有多个ul怎么办？很简单，记住那句话，只有wrapper里的第一个子元素（ul）才可以被实例化滚动：&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&amp;lt;div id=&amp;quot;wrapper&amp;quot;&amp;gt;//overflow:hidden;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &amp;lt;div id=&amp;quot;first&amp;quot;&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        //只有第一个DOM结构(ul)被实例化，这个DOM可以纵向或者横向的滚动，&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        //多出的内容会被wrapper的样式hidden&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &amp;lt;ul&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &amp;lt;li&amp;gt;1&amp;lt;/li&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &amp;lt;li&amp;gt;2&amp;lt;/li&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &amp;lt;li&amp;gt;3&amp;lt;/li&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &amp;lt;/ul&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &amp;lt;ul&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &amp;lt;li&amp;gt;4&amp;lt;/li&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &amp;lt;li&amp;gt;5&amp;lt;/li&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &amp;lt;li&amp;gt;6&amp;lt;/li&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        &amp;lt;/ul&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &amp;lt;/div&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;lt;/div&amp;gt;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;看到了吧，只有first会被实例化。 注意：这里第一个DOM结构的ID（first）可以不写，我只是为了方便大家识别才写了个ID，但是最外层的ID（wrapper）一定要写，因为在JS实例化的时候需要填写这个ID：&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;var myScroll = new iScroll(&amp;quot;wrapper&amp;quot;);&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;iScroll应该如何实例化：&lt;/p&gt;
&lt;p&gt;既然说道了实例化，我们应该在什么时候实例化？据说实例化的方法有很多，但是我没用过，我只说一种：&lt;/p&gt;
&lt;p&gt;（1）在HTML（uw3c.html）页面底部（body之后html之前）加载iscroll.js与当前页面的uw3c.js,这样能确保HTML的DOM结构能加载出来。&lt;/p&gt;
&lt;p&gt;（2）在JS插入页面DOM结构和数据之前实例化iScroll，也就是在JS的最开始实例化，因为之后可能会使用JS来插入DOM或者数据，这样以来能确保在插入数据之前iScroll已经实例化了。&lt;/p&gt;
&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;18&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;19&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;20&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;21&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;22&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;HTML://HTML结构&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;lt;html &amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &amp;lt;body&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;     ...code...&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &amp;lt;/body&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;     //插入iscroll.js文件&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;   &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;js/iscroll.js&amp;quot; &amp;gt; &amp;lt;/script &amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    //插入本页面JS文件&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;js/uw3c.js&amp;quot; &amp;gt; &amp;lt;/script &amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; JS://JS文件内容&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; var myscroll;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; function iscroll(data)&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;      //实例化iScroll&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;     myscroll=new iScroll(&amp;quot;wrapper&amp;quot;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;     pageData(data);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; &amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; function pageData(obj)&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;     $(&amp;quot;body&amp;quot;).html(obj);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;     myscroll.refresh();//当DOM结构发生变化的时候，需要刷新iScroll&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; &amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt; iscroll(&amp;quot;&amp;lt;div&amp;gt;pagedata&amp;lt;/div&amp;gt;&amp;quot;);&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;iScroll中的参数：&lt;/p&gt;
&lt;p&gt;在实例化iScroll的时候，可以传入两个参数，第一个参数是实例化的外层的DOM的ID，第二个参数是iScroll执行方法的对象：&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;var myscroll=new iScroll(&amp;quot;wrapper&amp;quot;,&amp;#123;hScrollbar:false&amp;#125;);&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;或者&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;var opts = &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                vScroll:false,//禁止垂直滚动&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                snap:true,//执行传送带效果&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;                hScrollbar:false//隐藏水平方向上的滚动条&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;            &amp;#125;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;var myscroll = new iScroll(&amp;quot;wrapper&amp;quot;,opts);&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;第二个参数内容如下，这个参数会控制iScroll的效果：&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;hScroll        false 禁止横向滚动 true横向滚动 默认为true&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;vScroll        false 禁止垂直滚动 true垂直滚动 默认为true&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;hScrollbar     false隐藏水平方向上的滚动条&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;vScrollbar     false 隐藏垂直方向上的滚动条&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;fadeScrollbar  false 指定在无渐隐效果时隐藏滚动条&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;hideScrollbar  在没有用户交互时隐藏滚动条 默认为true&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;bounce         启用或禁用边界的反弹，默认为true&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;momentum       启用或禁用惯性，默认为true，&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;               此参数在你想要保存资源的时候非常有用&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;lockDirection  false取消拖动方向的锁定，&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;               true拖动只能在一个方向上（up/down 或者left/right）&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;iScroll中的方法：&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;当然在第二个参数中，也有一些方法可以执行：&lt;/p&gt;
&lt;p&gt;(1)scrollTo(x, y, time, relative)方法：传入4个参数：X轴滚动距离，Y轴滚动距离，效果时间，是否相对当前位置。所以例如：&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;//在200毫秒的时间内，Y轴向上滚动100像素；&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;uw3c.scrollTo(0, -100, 200)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;//在200毫秒的时间内，相对于当前位置，X轴向左滚动100像素；&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;uw3c.scrollTo(-100, 0, 200, true)&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;(2)refresh()方法：在DOM结构发生改变之后，需要刷新iScroll，否则滚动插件会实例化的不准确：&lt;/p&gt;
&lt;p&gt;uw3c.refresh();//刷新iScroll&lt;/p&gt;
&lt;p&gt;(3)onPosChange,有没有一个方法能返回位置的变化？你可以查询一下自己所用的iScroll中有没有onPosChange方法：&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;onPosChange:function(x,y)&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    if(y &amp;lt; -200)&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;     //如果Y周向上滚动200像素，$(&amp;quot;#uw3c&amp;quot;)就显示，否则就隐藏。&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        $(&amp;quot;#uw3c&amp;quot;).show();&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &amp;#125;else&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;        $(&amp;quot;#uw3c&amp;quot;).hide();&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;（4）onScrollEnd：滚动结束时执行的事件，如果想在滚动结束时出发摸个事件，这个方法就拍上用处了：&lt;br&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;//滚动结束后，执行的方法，滚动后会出现提示框alert(&amp;quot;uw3c.com&amp;quot;)&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;onScrollEnd:function()&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    alert(&amp;quot;uw3c.com&amp;quot;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;（5）onRefresh：在DOM结构发生改变之后，需要刷新iScroll，否则滚动插件会实例化的不准确，onRefresh是刷新完iScroll会执行的方法。&lt;br&gt;（6）onBeforeScrollStart：开始滚动前的时间回调，默认是阻止浏览器默认行为 。&lt;br&gt;（7）onScrollStart：开始滚动的回调。&lt;br&gt;（8）onBeforeScrollMove：在内容移动前的回调。&lt;br&gt;（9）onScrollMove：内容移动的回调。&lt;br&gt;（10）onBeforeScrollEnd：在滚动结束前的回调。&lt;br&gt;（11）onTouchEnd：手离开屏幕后的回调。&lt;br&gt;（12）onDestroy：销毁实例的回调。&lt;br&gt;
    
    </summary>
    
      <category term="javascript" scheme="http://sunhao.win/categories/javascript/"/>
    
    
      <category term="js" scheme="http://sunhao.win/tags/js/"/>
    
      <category term="mobile" scheme="http://sunhao.win/tags/mobile/"/>
    
  </entry>
  
  <entry>
    <title>js-animate-canvas满屏小球动画</title>
    <link href="http://sunhao.win/articles/js-animate-canvas.html"/>
    <id>http://sunhao.win/articles/js-animate-canvas.html</id>
    <published>2017-08-17T06:43:43.000Z</published>
    <updated>2017-08-17T06:45:51.846Z</updated>
    
    <content type="html"><![CDATA[<p>逻辑简单  效果不错<br><a href="https://codepen.io/whqet/pen/bNWGaj" target="_blank" rel="external">https://codepen.io/whqet/pen/bNWGaj</a></p>
<canvas id="motion">Canvas is not supported in your browser.</canvas>

<p>body {<br>  overflow:hidden;<br>}</p>
<a id="more"></a>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// requestAnimationFrame polyfill by Erik Möller.</span></div><div class="line"><span class="keyword">if</span> (!<span class="built_in">Date</span>.now)</div><div class="line">    <span class="built_in">Date</span>.now = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123; <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Date</span>().getTime(); &#125;;</div><div class="line"></div><div class="line">(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</div><div class="line"><span class="meta">    'use strict'</span>;</div><div class="line">    </div><div class="line">    <span class="keyword">var</span> vendors = [<span class="string">'webkit'</span>, <span class="string">'moz'</span>];</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; vendors.length &amp;&amp; !<span class="built_in">window</span>.requestAnimationFrame; ++i) &#123;</div><div class="line">        <span class="keyword">var</span> vp = vendors[i];</div><div class="line">        <span class="built_in">window</span>.requestAnimationFrame = <span class="built_in">window</span>[vp+<span class="string">'RequestAnimationFrame'</span>];</div><div class="line">        <span class="built_in">window</span>.cancelAnimationFrame = (<span class="built_in">window</span>[vp+<span class="string">'CancelAnimationFrame'</span>]</div><div class="line">                                   || <span class="built_in">window</span>[vp+<span class="string">'CancelRequestAnimationFrame'</span>]);</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">if</span> (<span class="regexp">/iP(ad|hone|od).*OS 6/</span>.test(<span class="built_in">window</span>.navigator.userAgent) <span class="comment">// iOS6 is buggy</span></div><div class="line">        || !<span class="built_in">window</span>.requestAnimationFrame || !<span class="built_in">window</span>.cancelAnimationFrame) &#123;</div><div class="line">        <span class="keyword">var</span> lastTime = <span class="number">0</span>;</div><div class="line">        <span class="built_in">window</span>.requestAnimationFrame = <span class="function"><span class="keyword">function</span>(<span class="params">callback</span>) </span>&#123;</div><div class="line">            <span class="keyword">var</span> now = <span class="built_in">Date</span>.now();</div><div class="line">            <span class="keyword">var</span> nextTime = <span class="built_in">Math</span>.max(lastTime + <span class="number">16</span>, now);</div><div class="line">            <span class="keyword">return</span> setTimeout(<span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123; callback(lastTime = nextTime); &#125;,</div><div class="line">                              nextTime - now);</div><div class="line">        &#125;;</div><div class="line">        <span class="built_in">window</span>.cancelAnimationFrame = clearTimeout;</div><div class="line">    &#125;</div><div class="line">&#125;());</div><div class="line"></div><div class="line"><span class="keyword">var</span> getRandomColor = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</div><div class="line">  <span class="keyword">return</span> <span class="string">'#'</span>+(<span class="built_in">Math</span>.random()*<span class="number">0xffffff</span>&lt;&lt;<span class="number">0</span>).toString(<span class="number">16</span>);</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="keyword">var</span> canvas = <span class="built_in">document</span>.getElementById(<span class="string">"motion"</span>), </div><div class="line">    c = canvas.getContext(<span class="string">"2d"</span>),</div><div class="line">    particles = &#123;&#125;,</div><div class="line">    particleIndex = <span class="number">0</span>,</div><div class="line">    particleNum = <span class="number">0.2</span>;</div><div class="line"></div><div class="line">canvas.width = <span class="built_in">window</span>.innerWidth;</div><div class="line">canvas.height = <span class="built_in">window</span>.innerHeight;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">Particle</span>(<span class="params"></span>)</span>&#123;</div><div class="line">  <span class="keyword">this</span>.x = canvas.width/<span class="number">2</span>;</div><div class="line">  <span class="keyword">this</span>.y = canvas.height/<span class="number">2</span>;</div><div class="line"></div><div class="line">  <span class="keyword">this</span>.vx = <span class="built_in">Math</span>.random() * <span class="number">6</span> - <span class="number">3</span>;</div><div class="line">  <span class="keyword">this</span>.vy = <span class="built_in">Math</span>.random() * <span class="number">4</span> - <span class="number">2</span>;</div><div class="line"></div><div class="line">  <span class="keyword">this</span>.growth = ( <span class="built_in">Math</span>.abs(<span class="keyword">this</span>.vx) + <span class="built_in">Math</span>.abs(<span class="keyword">this</span>.vy) ) * <span class="number">0.007</span>;</div><div class="line"></div><div class="line">  particleIndex++;</div><div class="line">  particles[particleIndex] = <span class="keyword">this</span>;</div><div class="line">  <span class="keyword">this</span>.id = particleIndex;</div><div class="line">  <span class="keyword">this</span>.size = <span class="built_in">Math</span>.random() * <span class="number">1</span>;</div><div class="line">  <span class="keyword">this</span>.color = getRandomColor();</div><div class="line">&#125;</div><div class="line"></div><div class="line">Particle.prototype.draw = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</div><div class="line">  <span class="keyword">this</span>.x += <span class="keyword">this</span>.vx;</div><div class="line">  <span class="keyword">this</span>.y += <span class="keyword">this</span>.vy;</div><div class="line"></div><div class="line">  <span class="keyword">this</span>.size += <span class="keyword">this</span>.growth;</div><div class="line">  <span class="keyword">if</span>(<span class="keyword">this</span>.x &gt; canvas.width || <span class="keyword">this</span>.y &gt; canvas.height)&#123;</div><div class="line">    <span class="keyword">delete</span> particles[<span class="keyword">this</span>.id];</div><div class="line">  &#125;</div><div class="line"></div><div class="line">  c.fillStyle = <span class="keyword">this</span>.color;</div><div class="line">  c.beginPath();</div><div class="line">  c.arc(<span class="keyword">this</span>.x, <span class="keyword">this</span>.y, <span class="keyword">this</span>.size,<span class="number">0</span>*<span class="built_in">Math</span>.PI,<span class="number">2</span>*<span class="built_in">Math</span>.PI);</div><div class="line">  c.fill();</div><div class="line">&#125;;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">animate</span>(<span class="params"></span>)</span>&#123;</div><div class="line">  requestAnimationFrame( animate );</div><div class="line">  </div><div class="line">  c.fillStyle = <span class="string">"#000"</span>;</div><div class="line">  c.fillRect(<span class="number">0</span>,<span class="number">0</span>,canvas.width,canvas.height);</div><div class="line">  <span class="keyword">if</span>(<span class="built_in">Math</span>.random() &gt; particleNum)&#123;</div><div class="line">    <span class="keyword">new</span> Particle();</div><div class="line">  &#125;</div><div class="line">  <span class="keyword">for</span>(<span class="keyword">var</span> i <span class="keyword">in</span> particles)&#123;</div><div class="line">    particles[i].draw();</div><div class="line">  &#125;</div><div class="line">&#125;</div><div class="line">requestAnimationFrame( animate );</div></pre></td></tr></table></figure>
]]></content>
    
    <summary type="html">
    
      &lt;p&gt;逻辑简单  效果不错&lt;br&gt;&lt;a href=&quot;https://codepen.io/whqet/pen/bNWGaj&quot; target=&quot;_blank&quot; rel=&quot;external&quot;&gt;https://codepen.io/whqet/pen/bNWGaj&lt;/a&gt;&lt;/p&gt;
&lt;canvas id=&quot;motion&quot;&gt;Canvas is not supported in your browser.&lt;/canvas&gt;

&lt;p&gt;body {&lt;br&gt;  overflow:hidden;&lt;br&gt;}&lt;/p&gt;
    
    </summary>
    
      <category term="javascript" scheme="http://sunhao.win/categories/javascript/"/>
    
    
      <category term="js" scheme="http://sunhao.win/tags/js/"/>
    
      <category term="animate" scheme="http://sunhao.win/tags/animate/"/>
    
  </entry>
  
  <entry>
    <title>element-vue-study</title>
    <link href="http://sunhao.win/articles/element-vue-study.html"/>
    <id>http://sunhao.win/articles/element-vue-study.html</id>
    <published>2017-07-18T07:29:55.000Z</published>
    <updated>2017-07-20T07:49:10.609Z</updated>
    
    <content type="html"><![CDATA[<p>一致<br>Consistency</p>
<p>反馈<br>Feedback</p>
<p>效率<br>Efficiency</p>
<p>可控<br>Controllability</p>
<p>关于导航的设计</p>
<p>如果导航较多  可以左侧分类<br>如果导航较少  可以顶部导航</p>
<p>主色  辅助色 中性色<br>主场景         主要表现<br>副场景        表现用途<br>边框 文字   表现层次</p>
<p> var arr = [2, 3, 4];<br>        var checkNum = 2;<br>        arr.filter((function(checkNum) {</p>
<pre><code>    return function(num) {

        return num &gt; checkNum;
    }
})(checkNum))
</code></pre><p>isright = !false;<br>var cb = isright? (isright++) : 10;<br>console.log(cb)<br>console.log(isright)</p>
<p>  methods: {<br>            queryData(queryString, cb) {<br>                let citys = this.citys<br>                var result = queryString ? citys.filter(((queryString) =&gt; {<br>                    return (city) =&gt; {<br>                        return city.value.indexOf(queryString.toLowerCase()) == 0<br>                    }<br>                })(queryString)) : citys<br>                cb(result)<br>            },<br>            selectCity(item) {<br>                console.log(item)<br>            }</p>
<pre><code>}
</code></pre><a id="more"></a>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;一致&lt;br&gt;Consistency&lt;/p&gt;
&lt;p&gt;反馈&lt;br&gt;Feedback&lt;/p&gt;
&lt;p&gt;效率&lt;br&gt;Efficiency&lt;/p&gt;
&lt;p&gt;可控&lt;br&gt;Controllability&lt;/p&gt;
&lt;p&gt;关于导航的设计&lt;/p&gt;
&lt;p&gt;如果导航较多  可以左侧分类&lt;br&gt;如果导航较少  可以顶部导航&lt;/p&gt;
&lt;p&gt;主色  辅助色 中性色&lt;br&gt;主场景         主要表现&lt;br&gt;副场景        表现用途&lt;br&gt;边框 文字   表现层次&lt;/p&gt;
&lt;p&gt; var arr = [2, 3, 4];&lt;br&gt;        var checkNum = 2;&lt;br&gt;        arr.filter((function(checkNum) {&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    return function(num) {

        return num &amp;gt; checkNum;
    }
})(checkNum))
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;isright = !false;&lt;br&gt;var cb = isright? (isright++) : 10;&lt;br&gt;console.log(cb)&lt;br&gt;console.log(isright)&lt;/p&gt;
&lt;p&gt;  methods: {&lt;br&gt;            queryData(queryString, cb) {&lt;br&gt;                let citys = this.citys&lt;br&gt;                var result = queryString ? citys.filter(((queryString) =&amp;gt; {&lt;br&gt;                    return (city) =&amp;gt; {&lt;br&gt;                        return city.value.indexOf(queryString.toLowerCase()) == 0&lt;br&gt;                    }&lt;br&gt;                })(queryString)) : citys&lt;br&gt;                cb(result)&lt;br&gt;            },&lt;br&gt;            selectCity(item) {&lt;br&gt;                console.log(item)&lt;br&gt;            }&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;}
&lt;/code&gt;&lt;/pre&gt;
    
    </summary>
    
    
  </entry>
  
  <entry>
    <title>node-js-module-study</title>
    <link href="http://sunhao.win/articles/node-js-module-study.html"/>
    <id>http://sunhao.win/articles/node-js-module-study.html</id>
    <published>2017-07-08T06:08:53.000Z</published>
    <updated>2017-07-15T02:13:29.838Z</updated>
    
    <content type="html"><![CDATA[<p>browserify<br>cross-env</p>
<p><a href="http://www.cnblogs.com/libin-1/p/6254390.html插件开发" target="_blank" rel="external">http://www.cnblogs.com/libin-1/p/6254390.html插件开发</a></p>
<p>promise</p>
<p><a href="https://www.kancloud.cn/yunye/axios/234846" target="_blank" rel="external">https://www.kancloud.cn/yunye/axios/234846</a></p>
<p>webpack-merge</p>
<p>url-loader</p>
<p>vuex<br>vue把事件驱动    和  行为变化  分离开 </p>
<p>因为页面多，行为变化具有公共调控性。  所以 行为从事件分离开。   虽然麻烦  但是对于多页面挺有用</p>
<p>actions</p>
<p>mutations</p>
<a id="more"></a>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;browserify&lt;br&gt;cross-env&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.cnblogs.com/libin-1/p/6254390.html插件开发&quot; target=&quot;_blank&quot; rel=&quot;external&quot;&gt;http://www.cnblogs.com/libin-1/p/6254390.html插件开发&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;promise&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://www.kancloud.cn/yunye/axios/234846&quot; target=&quot;_blank&quot; rel=&quot;external&quot;&gt;https://www.kancloud.cn/yunye/axios/234846&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;webpack-merge&lt;/p&gt;
&lt;p&gt;url-loader&lt;/p&gt;
&lt;p&gt;vuex&lt;br&gt;vue把事件驱动    和  行为变化  分离开 &lt;/p&gt;
&lt;p&gt;因为页面多，行为变化具有公共调控性。  所以 行为从事件分离开。   虽然麻烦  但是对于多页面挺有用&lt;/p&gt;
&lt;p&gt;actions&lt;/p&gt;
&lt;p&gt;mutations&lt;/p&gt;
    
    </summary>
    
    
  </entry>
  
  <entry>
    <title>利用docker实现mysql主从同步/读写分离，附赠docker搭建mycat读写分离。</title>
    <link href="http://sunhao.win/articles/mysql-replication.html"/>
    <id>http://sunhao.win/articles/mysql-replication.html</id>
    <published>2017-07-01T06:42:05.000Z</published>
    <updated>2017-07-11T06:59:16.623Z</updated>
    
    <content type="html"><![CDATA[<h2 id="利用docker实现mysql主从同步-读写分离"><a href="#利用docker实现mysql主从同步-读写分离" class="headerlink" title="利用docker实现mysql主从同步/读写分离"></a>利用docker实现mysql主从同步/读写分离</h2><p>为了保证数据的完整和安全，mysql设计了主从同步，一个挂掉还可以用另个。最近重构论坛，想来改成主从吧。担心失误，就先拿docker练练手。<br>有错误或者不理解的地方，可以联系本人邮箱sunhaokk@qq.com。</p>
<p>通过本文实际你会操作到。</p>
<ol>
<li>mysql的主从同步</li>
<li>docker镜像和容器的创建</li>
<li>docker容器间的数据传递</li>
<li>mycat入门</li>
</ol>
<p>以下需要大于100的智商和mysql基础docker基础，linux基础。</p>
<p>没有也没事，就是看着会有点吃力。</p>
<p>环境是centos，mycat是1.6.docker是1.12.6</p>
<h3 id="下载mysql镜像。"><a href="#下载mysql镜像。" class="headerlink" title="下载mysql镜像。"></a>下载mysql镜像。</h3><pre><code>docker pull mysql


ps:如果下载太慢，请添加腾讯源,依次执行
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">echo &quot;OPTIONS=&apos;--registry-mirror=https://mirror.ccs.tencentyun.com&apos;&quot; &gt;&gt; /etc/sysconfig/docker</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">systemctl daemon-reload</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">service docker restart</div></pre></td></tr></table></figure>
<p>或者直接去阿里仓库下<a href="https://dev.aliyun.com/search.html把上面的--registry-mirror=https://mirror.ccs.tencentyun.com换成你的专属源就可以" target="_blank" rel="external">https://dev.aliyun.com/search.html把上面的--registry-mirror=https://mirror.ccs.tencentyun.com换成你的专属源就可以</a></p>
<p>下载完输入</p>
<pre><code>docker images
</code></pre><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE</div><div class="line">docker.io/mysql             latest              44a8e1a5c0b2        8 days ago          407 MB</div></pre></td></tr></table></figure>
<h3 id="利用mysql镜像，创建用于主从同步的两个新镜像。"><a href="#利用mysql镜像，创建用于主从同步的两个新镜像。" class="headerlink" title="利用mysql镜像，创建用于主从同步的两个新镜像。"></a>利用mysql镜像，创建用于主从同步的两个新镜像。</h3><p>我们当前所在的服务器叫<strong>宿主服务器</strong>，</p>
<p>我们要利用docker 虚拟两个docker容器服务器，一个主服务器，一个从服务器。</p>
<a id="more"></a>
<h4 id="创建master-主-和slave-从-两个文件夹"><a href="#创建master-主-和slave-从-两个文件夹" class="headerlink" title="创建master(主)和slave(从)两个文件夹"></a>创建master(主)和slave(从)两个文件夹</h4><pre><code>/usr/mysql/master
/usr/mysql/slave
</code></pre><h4 id="在master和slave文件夹下-创建-Dockerfile-内容为"><a href="#在master和slave文件夹下-创建-Dockerfile-内容为" class="headerlink" title="在master和slave文件夹下  创建 Dockerfile 内容为"></a>在master和slave文件夹下  创建 Dockerfile 内容为</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">FROM mysql</div><div class="line"></div><div class="line">COPY my.cnf /etc/mysql/  </div><div class="line"></div><div class="line">EXPOSE 3306</div><div class="line"></div><div class="line">CMD [&quot;mysqld&quot;]</div></pre></td></tr></table></figure>
<h4 id="在master文件夹下-创建-my-cnf-内容为"><a href="#在master文件夹下-创建-my-cnf-内容为" class="headerlink" title="在master文件夹下  创建 my.cnf 内容为"></a>在master文件夹下  创建 my.cnf 内容为</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[mysqld]</div><div class="line"></div><div class="line">log-bin=mysql-bin   //[必须]启用二进制日志</div><div class="line"></div><div class="line">server-id=1//[必须]服务器唯一ID，默认是1，一般取IP最后一段，这里看情况分配</div></pre></td></tr></table></figure>
<hr>
<h4 id="在slave文件夹下-创建-my-cnf-内容为"><a href="#在slave文件夹下-创建-my-cnf-内容为" class="headerlink" title="在slave文件夹下  创建 my.cnf 内容为"></a>在slave文件夹下  创建 my.cnf 内容为</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[mysqld]</div><div class="line"></div><div class="line">log-bin=mysql-bin   //[必须]启用二进制日志</div><div class="line"></div><div class="line">server-id=2//[必须]服务器唯一ID，默认是1，一般取IP最后一段，这里看情况分配</div></pre></td></tr></table></figure>
<h4 id="切换到master目录下构建master-mysql镜像"><a href="#切换到master目录下构建master-mysql镜像" class="headerlink" title="切换到master目录下构建master/mysql镜像"></a>切换到master目录下构建master/mysql镜像</h4><pre><code>docker build -t master/mysql .
</code></pre><p>（命令最后有个.，不要忘记，代表当前目录）</p>
<h4 id="然后切换到slave目录下构建slave-mysql镜像"><a href="#然后切换到slave目录下构建slave-mysql镜像" class="headerlink" title="然后切换到slave目录下构建slave/mysql镜像"></a>然后切换到slave目录下构建slave/mysql镜像</h4><pre><code>docker build -t slave/mysql .
</code></pre><p>（命令最后有个.，不要忘记，代表当前目录）</p>
<h4 id="查看是否创建成功"><a href="#查看是否创建成功" class="headerlink" title="查看是否创建成功"></a>查看是否创建成功</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@VM_118_220_centos ~]# docker images</div><div class="line">REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE</div><div class="line">slave/mysql                 latest              8c496048d7ba        About an hour ago   407 MB</div><div class="line">master/mysql                latest              7be30b0b631b        2 hours ago         407 MB</div><div class="line">docker.io/mysql             latest              44a8e1a5c0b2        8 days ago          407 MB</div></pre></td></tr></table></figure>
<h3 id="用镜像创建容器"><a href="#用镜像创建容器" class="headerlink" title="用镜像创建容器"></a>用镜像创建容器</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">docker run -p 3306 --name mysql-master -e MYSQL_ROOT_PASSWORD=mysql -d master/mysql</div><div class="line"></div><div class="line">docker run -p 3306 --name mysql-slave -e MYSQL_ROOT_PASSWORD=mysql -d slave/mysql</div></pre></td></tr></table></figure>
<h4 id="从这里开始，建议打开两个终端窗口，方便操作。"><a href="#从这里开始，建议打开两个终端窗口，方便操作。" class="headerlink" title="从这里开始，建议打开两个终端窗口，方便操作。"></a>从这里开始，建议打开两个终端窗口，方便操作。</h4><h5 id="master终端执行"><a href="#master终端执行" class="headerlink" title="master终端执行"></a>master终端执行</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">docker exec -it mysql-master bash</div><div class="line"></div><div class="line">mysql -uroot -p</div></pre></td></tr></table></figure>
<p>输入密码mysql进入到mysql环境</p>
<h5 id="slave终端执行"><a href="#slave终端执行" class="headerlink" title="slave终端执行"></a>slave终端执行</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">docker exec -it mysql-slave bash</div><div class="line"></div><div class="line">mysql -uroot -p</div></pre></td></tr></table></figure>
<p>输入密码mysql进入到mysql环境</p>
<h3 id="mysql主从配置"><a href="#mysql主从配置" class="headerlink" title="mysql主从配置"></a>mysql主从配置</h3><p>mysql配置</p>
<h4 id="在主容器mysql中输入以下命令："><a href="#在主容器mysql中输入以下命令：" class="headerlink" title="在主容器mysql中输入以下命令："></a>在主容器mysql中输入以下命令：</h4><figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">mysql&gt;GRANT REPLICATION SLAVE ON *.* TO 'user'@'192.168.99.100' IDENTIFIED BY 'mysql';（指定ip）或者</div><div class="line"></div><div class="line">mysql&gt;GRANT REPLICATION SLAVE ON *.* to 'user'@'%' identified by 'mysql';（所有ip）</div></pre></td></tr></table></figure>
<p>然后查看主容器数据库状态：</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"></div><div class="line">mysql&gt; show master status;</div><div class="line">+------------------+----------+--------------+------------------+-------------------+</div><div class="line">| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |</div><div class="line">+------------------+----------+--------------+------------------+-------------------+</div><div class="line">| mysql-bin.000003 |     1338 |              |                  |                   |</div><div class="line">+------------------+----------+--------------+------------------+-------------------+</div><div class="line">1 row in set (0.00 sec)</div></pre></td></tr></table></figure>
<p>记录File 的值和Position的值。</p>
<p>下面要用到，到这里为止，主库千万不要再做任何操作，防止状态改变。</p>
<h4 id="然后我们配置一下从库"><a href="#然后我们配置一下从库" class="headerlink" title="然后我们配置一下从库"></a>然后我们配置一下从库</h4><h4 id="查看master-mysql的对外端口号"><a href="#查看master-mysql的对外端口号" class="headerlink" title="查看master/mysql的对外端口号"></a>查看master/mysql的对外端口号</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">docker ps</div><div class="line">CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES</div><div class="line">8d1e3b87d499        slave/mysql         &quot;docker-entrypoint.sh&quot;   2 hours ago         Up 2 hours          0.0.0.0:32769-&gt;3306/tcp   mysql-slave</div><div class="line">980e5ea48152        master/mysql        &quot;docker-entrypoint.sh&quot;   2 hours ago         Up 2 hours          0.0.0.0:32768-&gt;3306/tcp   mysql-master</div></pre></td></tr></table></figure>
<p>0.0.0.0:32768-&gt;3306/tcp其中32768为master的端口</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">mysql&gt;change master to</div><div class="line"></div><div class="line">master_host='x.x.x.x',</div><div class="line"></div><div class="line">master_user='user',</div><div class="line"></div><div class="line">master_log_file='mysql-bin.000003',</div><div class="line"></div><div class="line">master_log_pos=1201,</div><div class="line"></div><div class="line">master_port=32768,</div><div class="line"></div><div class="line">master_password='mysql';</div><div class="line"></div><div class="line">Query OK, 0 rows affected, 2 warnings (0.03 sec)</div><div class="line"></div><div class="line">mysql&gt; start slave;</div><div class="line">Query OK, 0 rows affected (0.01 sec)</div></pre></td></tr></table></figure>
<p>master_host=’x.x.x.x’ //这里填master主机ip</p>
<p>master_log_file=’mysql-bin.000003’,  //这里填写File 的值</p>
<p>master_log_pos=1338,//这里填写Position的值。</p>
<p>mysql&gt; start slave;//启动从服务器复制功能</p>
<p>如果不小心配置错,输入mysql&gt; stop slave;然后重新录入一遍</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">mysql&gt;change master to</div><div class="line"></div><div class="line">master_host='x.x.x.x',</div><div class="line"></div><div class="line">master_user='user',</div><div class="line"></div><div class="line">master_log_file='mysql-bin.000003',</div><div class="line"></div><div class="line">master_log_pos=1201,</div><div class="line"></div><div class="line">master_port=32768,</div><div class="line"></div><div class="line">master_password='mysql';</div></pre></td></tr></table></figure>
<p>就可以了</p>
<h3 id="检查主从连接状态"><a href="#检查主从连接状态" class="headerlink" title="检查主从连接状态"></a>检查主从连接状态</h3><figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show slave status\G</div><div class="line">*************************** 1. row ***************************</div><div class="line">               Slave_IO_State: Waiting for master to send event</div><div class="line">                  Master_Host: x.x.x.x</div><div class="line">                  Master_User: user</div><div class="line">                  Master_Port: 32768</div><div class="line">                Connect_Retry: 60</div><div class="line">              Master_Log_File: mysql-bin.000003</div><div class="line">          Read_Master_Log_Pos: 1338</div><div class="line">               Relay_Log_File: 8d1e3b87d499-relay-bin.000002</div><div class="line">                Relay_Log_Pos: 1221</div><div class="line">        Relay_Master_Log_File: mysql-bin.000003</div><div class="line">             Slave_IO_Running: Yes</div><div class="line">            Slave_SQL_Running: Yes</div><div class="line">              Replicate_Do_DB: </div><div class="line">          Replicate_Ignore_DB: </div><div class="line">           Replicate_Do_Table: </div><div class="line">       Replicate_Ignore_Table: </div><div class="line">      Replicate_Wild_Do_Table: </div><div class="line">  Replicate_Wild_Ignore_Table: </div><div class="line">                   Last_Errno: 0</div><div class="line">                   Last_Error: </div><div class="line">                 Skip_Counter: 0</div><div class="line">          Exec_Master_Log_Pos: 1338</div><div class="line">              Relay_Log_Space: 1435</div><div class="line">              Until_Condition: None</div><div class="line">               Until_Log_File: </div><div class="line">                Until_Log_Pos: 0</div><div class="line">           Master_SSL_Allowed: No</div><div class="line">           Master_SSL_CA_File: </div><div class="line">           Master_SSL_CA_Path: </div><div class="line">              Master_SSL_Cert: </div><div class="line">            Master_SSL_Cipher: </div><div class="line">               Master_SSL_Key: </div><div class="line">        Seconds_Behind_Master: 0</div><div class="line">Master_SSL_Verify_Server_Cert: No</div><div class="line">                Last_IO_Errno: 0</div><div class="line">                Last_IO_Error: </div><div class="line">               Last_SQL_Errno: 0</div><div class="line">               Last_SQL_Error: </div><div class="line">  Replicate_Ignore_Server_Ids: </div><div class="line">             Master_Server_Id: 1</div><div class="line">                  Master_UUID: cd327a00-5e18-11e7-98f7-0242ac110006</div><div class="line">             Master_Info_File: /var/lib/mysql/master.info</div><div class="line">                    SQL_Delay: 0</div><div class="line">          SQL_Remaining_Delay: NULL</div><div class="line">      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates</div><div class="line">           Master_Retry_Count: 86400</div><div class="line">                  Master_Bind: </div><div class="line">      Last_IO_Error_Timestamp: </div><div class="line">     Last_SQL_Error_Timestamp: </div><div class="line">               Master_SSL_Crl: </div><div class="line">           Master_SSL_Crlpath: </div><div class="line">           Retrieved_Gtid_Set: </div><div class="line">            Executed_Gtid_Set: </div><div class="line">                Auto_Position: 0</div><div class="line">         Replicate_Rewrite_DB: </div><div class="line">                 Channel_Name: </div><div class="line">           Master_TLS_Version: </div><div class="line">1 row in set (0.00 sec)</div></pre></td></tr></table></figure>
<p>这两个必须是Yes 为No 或者connect说明没有连接上</p>
<p> Slave_IO_Running: Yes</p>
<p> Slave_SQL_Running: Yes</p>
<h3 id="测试主从连接"><a href="#测试主从连接" class="headerlink" title="测试主从连接"></a>测试主从连接</h3><p>注意设置主从后，操作只能在master终端上，slave上的操作不会同步到master上。</p>
<h4 id="登陆master终端，"><a href="#登陆master终端，" class="headerlink" title="登陆master终端，"></a>登陆master终端，</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div></pre></td><td class="code"><pre><div class="line">mysql&gt; create database sunhao;</div><div class="line">Query OK, 1 row affected (0.01 sec)</div><div class="line"></div><div class="line">mysql&gt; show databases;</div><div class="line">+--------------------+</div><div class="line">| Database           |</div><div class="line">+--------------------+</div><div class="line">| information_schema |</div><div class="line">| mysql              |</div><div class="line">| performance_schema |</div><div class="line">| sunhao             |</div><div class="line">| sys                |</div><div class="line">+--------------------+</div><div class="line">5 rows in set (0.00 sec)</div><div class="line"></div><div class="line"></div><div class="line">mysql&gt; use sunhao</div><div class="line">Database changed</div><div class="line">mysql&gt;  create table sunhao(id int(3),name char(10));</div><div class="line">Query OK, 0 rows affected (0.04 sec)</div><div class="line"></div><div class="line">mysql&gt; insert into sunhao values(1,&apos;xiaoshuai&apos;);</div><div class="line">Query OK, 1 row affected (0.01 sec)</div><div class="line"></div><div class="line">mysql&gt; select * from sunhao;</div><div class="line">+------+-----------+</div><div class="line">| id   | name      |</div><div class="line">+------+-----------+</div><div class="line">|    1 | xiaoshuai |</div><div class="line">+------+-----------+</div><div class="line">1 row in set (0.00 sec)</div></pre></td></tr></table></figure>
<h4 id="登陆slave服务器"><a href="#登陆slave服务器" class="headerlink" title="登陆slave服务器"></a>登陆slave服务器</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show databases;</div><div class="line">+--------------------+</div><div class="line">| Database           |</div><div class="line">+--------------------+</div><div class="line">| information_schema |</div><div class="line">| mysql              |</div><div class="line">| performance_schema |</div><div class="line">| sunhao             |</div><div class="line">| sys                |</div><div class="line">+--------------------+</div><div class="line">5 rows in set (0.00 sec)</div><div class="line"></div><div class="line">mysql&gt; use sunhao</div><div class="line">Reading table information for completion of table and column names</div><div class="line">You can turn off this feature to get a quicker startup with -A</div><div class="line">Database changed</div><div class="line"></div><div class="line">mysql&gt; select * from sunhao;</div><div class="line"></div><div class="line">+------+-----------+</div><div class="line">| id   | name      |</div><div class="line">+------+-----------+</div><div class="line">|    1 | xiaoshuai |</div><div class="line">+------+-----------+</div></pre></td></tr></table></figure>
<h4 id="如果主服务器已经存在应用数据，则在进行主从复制时，需要单独复制处理（注意此操作，如果对从服务器单独录入的数据，会被覆盖掉。）："><a href="#如果主服务器已经存在应用数据，则在进行主从复制时，需要单独复制处理（注意此操作，如果对从服务器单独录入的数据，会被覆盖掉。）：" class="headerlink" title="如果主服务器已经存在应用数据，则在进行主从复制时，需要单独复制处理（注意此操作，如果对从服务器单独录入的数据，会被覆盖掉。）："></a>如果主服务器已经存在应用数据，则在进行主从复制时，需要单独复制处理（注意此操作，如果对从服务器单独录入的数据，会被覆盖掉。）：</h4><p>这里我们做一次完整的测试</p>
<p>(1)在主服务器数据库插入新的数据，并进行锁表操作，不让数据再进行写入动作</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line">mysql&gt; insert into sunhao values(2,'xiaoshuai');</div><div class="line">Query OK, 1 row affected (0.01 sec)</div><div class="line"></div><div class="line">mysql&gt; select * from sunhao;                   </div><div class="line">+------+-----------+</div><div class="line">| id   | name      |</div><div class="line">+------+-----------+</div><div class="line">|    1 | xiaoshuai |</div><div class="line">|    2 | xiaoshuai |</div><div class="line">+------+-----------+</div><div class="line">2 rows in set (0.00 sec)</div><div class="line"></div><div class="line">mysql&gt; FLUSH TABLES WITH READ LOCK;</div><div class="line"></div><div class="line"></div><div class="line">mysql&gt; show full processlist; </div><div class="line"></div><div class="line">`</div></pre></td></tr></table></figure>
<p>(2)退出mysql，用mysqldump备份数据文件到/var/lib,然后顺便多余的用tar打包一下玩。哈哈。</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">mysql&gt; exit</div><div class="line">Bye</div><div class="line"></div><div class="line">root@980e5ea48152:/var/lib/mysql# mysqldump -u root -p  sunhao &gt; /var/lib/sunhao.dump    </div><div class="line">Enter password: </div><div class="line"></div><div class="line"></div><div class="line">root@980e5ea48152:/var/lib# tar -zcvf ./sunhao.dump .tar  ./sunhao.dump</div></pre></td></tr></table></figure>
<p>(3)打开宿主服务器，复制mysql主服务器文件sunhao.dump.tar。到宿主服务器</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">[root]# docker ps </div><div class="line">CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES</div><div class="line">8d1e3b87d499        slave/mysql         &quot;docker-entrypoint.sh&quot;   4 hours ago         Up 4 hours          0.0.0.0:32769-&gt;3306/tcp   mysql-slave</div><div class="line">980e5ea48152        master/mysql        &quot;docker-entrypoint.sh&quot;   4 hours ago         Up 4 hours          0.0.0.0:32768-&gt;3306/tcp   mysql-master</div><div class="line"></div><div class="line"></div><div class="line">mkdir -p /var/mydata</div><div class="line">docker cp 980e:/var/lib/sunhao.dump.tar /var/mydata/</div><div class="line"></div><div class="line">cd /var/mydata</div><div class="line">[root@VM_128_230_centos mydata]# ls</div><div class="line">sunhao.dump.tar</div></pre></td></tr></table></figure>
<p>解释:docker cp 980e:/var/lib/sunhao.dump.tar /var/mydata/</p>
<p>980e是980e5ea48152的缩写。保证不重复简写就可以</p>
<p>980e:/var/lib/sunhao.dump.tar   意思就是选中的容器下面你的文件下的sunhao.dump.tar文件</p>
<p>/var/mydata/ 目标文件</p>
<p>(4)在宿主主机上输入</p>
<pre><code>[root]# docker cp /var/mydata/sunhao.dump.tar 8d1e3b87d49936414c0e91ffdc60a054e7f4ef8b15baee295350565519abba0e:/var/lib/
</code></pre><p>(5)在从服务器上输入</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">root@8d1e3b87d499:/# cd /var/lib/</div><div class="line">root@8d1e3b87d499:/var/lib# tar -zcvf sunhao.dump.tar</div></pre></td></tr></table></figure>
<p>(6)在从服务器上输入</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">tar -zxvpf /var/lib/mysqlbak.sql.tar</div><div class="line"></div><div class="line">mysql -uroot -pmysql sunhao &lt; /var/lib/sunhao.dump;</div></pre></td></tr></table></figure>
<p>如果写入成功,这个时候就可以用select查询到数据。</p>
<p>(2)取消主服务器数据库锁定<br>    mysql&gt; UNLOCK TABLES;</p>
<h2 id="docker搭建mycat读写分离"><a href="#docker搭建mycat读写分离" class="headerlink" title="docker搭建mycat读写分离"></a>docker搭建mycat读写分离</h2><h3 id="制作mycat容器，并运行"><a href="#制作mycat容器，并运行" class="headerlink" title="制作mycat容器，并运行"></a>制作mycat容器，并运行</h3><h4 id="首先在本地新建个文件夹-usr-mycat。然后去mycat官网下载最新版本，这里我下载的是1-6版本。安装完解压到这里。"><a href="#首先在本地新建个文件夹-usr-mycat。然后去mycat官网下载最新版本，这里我下载的是1-6版本。安装完解压到这里。" class="headerlink" title="首先在本地新建个文件夹/usr/mycat。然后去mycat官网下载最新版本，这里我下载的是1.6版本。安装完解压到这里。"></a>首先在本地新建个文件夹/usr/mycat。然后去mycat官网下载最新版本，这里我下载的是1.6版本。安装完解压到这里。</h4><pre><code>http://dl.mycat.io/
[http://dl.mycat.io/1.6-RELEASE/](http://dl.mycat.io/1.6-RELEASE/ &quot;http://dl.mycat.io/1.6-RELEASE/&quot;)
</code></pre><h4 id="编写Dockerfile，内容为"><a href="#编写Dockerfile，内容为" class="headerlink" title="编写Dockerfile，内容为"></a>编写Dockerfile，内容为</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"># 来源镜像,因为mycat依赖java，所以这里直接选的java环境。</div><div class="line">FROM java</div><div class="line"></div><div class="line"></div><div class="line">RUN  mkdir -p /var/local/mycat/</div><div class="line"></div><div class="line"># Add复制Mycat到容器</div><div class="line">ADD  mycat/ /var/local/mycat/ </div><div class="line"></div><div class="line"></div><div class="line">ENTRYPOINT  [&quot;/var/local/mycat/bin/mycat&quot;,&quot;console&quot;,&quot;&amp;&quot;]</div><div class="line"></div><div class="line"># 对外端口</div><div class="line">EXPOSE 8066 9066</div><div class="line"></div><div class="line"># 启动控制台</div><div class="line">CMD  [&quot;/var/local/mycat/bin/mycat&quot;,&quot;console&quot;,&quot;&amp;&quot;]</div></pre></td></tr></table></figure>
<h4 id="先别急着构建镜像，我们先修改下mycat的配置文件。"><a href="#先别急着构建镜像，我们先修改下mycat的配置文件。" class="headerlink" title="先别急着构建镜像，我们先修改下mycat的配置文件。"></a>先别急着构建镜像，我们先修改下mycat的配置文件。</h4><pre><code>[root@centos mycat]# ll
total 15324
-rw-r--r-- 1 root root      357 Jul  5 15:26 Dockerfile
-rw-r--r-- 1 root root 15662280 Jul  3 15:07 Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
drwxr-xr-x 7 root root     4096 Jul  5 15:27 mycat
</code></pre><h4 id="在我用的1-6版本。mycat对外端口是注释掉的。我们要打开下。我们编辑-usr-mycat-mycat-conf-server-xml-找到第32-35行。去掉注释符号。"><a href="#在我用的1-6版本。mycat对外端口是注释掉的。我们要打开下。我们编辑-usr-mycat-mycat-conf-server-xml-找到第32-35行。去掉注释符号。" class="headerlink" title="在我用的1.6版本。mycat对外端口是注释掉的。我们要打开下。我们编辑/usr/mycat/mycat/conf/server.xml.找到第32-35行。去掉注释符号。"></a>在我用的1.6版本。mycat对外端口是注释掉的。我们要打开下。我们编辑/usr/mycat/mycat/conf/server.xml.找到第32-35行。去掉注释符号。<!-- --></h4><pre><code>&lt;!--
    &lt;property name=&quot;serverPort&quot;&gt;8066&lt;/property&gt; &lt;property name=&quot;managerPort&quot;&gt;9066&lt;/property&gt; 
    &lt;property name=&quot;idleTimeout&quot;&gt;300000&lt;/property&gt; &lt;property name=&quot;bindIp&quot;&gt;0.0.0.0&lt;/property&gt; 
    &lt;property name=&quot;frontWriteQueueSize&quot;&gt;4096&lt;/property&gt; &lt;property name=&quot;processors&quot;&gt;32&lt;/property&gt; --&gt;
</code></pre><h4 id="我们往下看-有这么几句。这里分别默认两个用户。-name为root的管理员，可以进行读写。和普通用户只能进行读。我们也可以手动创建修改，另外password是密码-schemas是用户所能操作的库。-在这里我什么都没有改。下面都是默认。"><a href="#我们往下看-有这么几句。这里分别默认两个用户。-name为root的管理员，可以进行读写。和普通用户只能进行读。我们也可以手动创建修改，另外password是密码-schemas是用户所能操作的库。-在这里我什么都没有改。下面都是默认。" class="headerlink" title="我们往下看  有这么几句。这里分别默认两个用户。   name为root的管理员，可以进行读写。和普通用户只能进行读。我们也可以手动创建修改，另外password是密码  schemas是用户所能操作的库。  在这里我什么都没有改。下面都是默认。"></a>我们往下看  有这么几句。这里分别默认两个用户。   name为root的管理员，可以进行读写。和普通用户只能进行读。我们也可以手动创建修改，另外password是密码  schemas是用户所能操作的库。  在这里我什么都没有改。下面都是默认。</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line">&lt;user name=&quot;root&quot;&gt;</div><div class="line">		&lt;property name=&quot;password&quot;&gt;123456&lt;/property&gt;</div><div class="line">		&lt;property name=&quot;schemas&quot;&gt;TESTDB&lt;/property&gt;</div><div class="line">		</div><div class="line">		&lt;!-- 表级 DML 权限设置 --&gt;</div><div class="line">		&lt;!-- 		</div><div class="line">		&lt;privileges check=&quot;false&quot;&gt;</div><div class="line">			&lt;schema name=&quot;TESTDB&quot; dml=&quot;0110&quot; &gt;</div><div class="line">				&lt;table name=&quot;tb01&quot; dml=&quot;0000&quot;&gt;&lt;/table&gt;</div><div class="line">				&lt;table name=&quot;tb02&quot; dml=&quot;1111&quot;&gt;&lt;/table&gt;</div><div class="line">			&lt;/schema&gt;</div><div class="line">		&lt;/privileges&gt;		</div><div class="line">		 --&gt;</div><div class="line">	&lt;/user&gt;</div><div class="line"></div><div class="line">	&lt;user name=&quot;user&quot;&gt;</div><div class="line">		&lt;property name=&quot;password&quot;&gt;user&lt;/property&gt;</div><div class="line">		&lt;property name=&quot;schemas&quot;&gt;TESTDB&lt;/property&gt;</div><div class="line">		&lt;property name=&quot;readOnly&quot;&gt;true&lt;/property&gt;</div><div class="line">	&lt;/user&gt;</div></pre></td></tr></table></figure>
<h4 id="我们编辑-usr-mycat-mycat-conf-schema-xml，这个是我们配置分片和逻辑库表，规则的地方，数据节点，和数据源。其中schema是我们所操作的逻辑库。默认为TESTDB。下面分别是各个逻辑表。在这里直接默认。我只是为了区分dh和db两个字的区别，把db1-3改了data1-3你们可以不用管。"><a href="#我们编辑-usr-mycat-mycat-conf-schema-xml，这个是我们配置分片和逻辑库表，规则的地方，数据节点，和数据源。其中schema是我们所操作的逻辑库。默认为TESTDB。下面分别是各个逻辑表。在这里直接默认。我只是为了区分dh和db两个字的区别，把db1-3改了data1-3你们可以不用管。" class="headerlink" title="我们编辑/usr/mycat/mycat/conf/schema.xml，这个是我们配置分片和逻辑库表，规则的地方，数据节点，和数据源。其中schema是我们所操作的逻辑库。默认为TESTDB。下面分别是各个逻辑表。在这里直接默认。我只是为了区分dh和db两个字的区别，把db1-3改了data1-3你们可以不用管。"></a>我们编辑/usr/mycat/mycat/conf/schema.xml，这个是我们配置分片和逻辑库表，规则的地方，数据节点，和数据源。其中schema是我们所操作的逻辑库。默认为TESTDB。下面分别是各个逻辑表。在这里直接默认。我只是为了区分dh和db两个字的区别，把db1-3改了data1-3你们可以不用管。</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div></pre></td><td class="code"><pre><div class="line">&lt;schema name=&quot;TESTDB&quot; checkSQLschema=&quot;false&quot; sqlMaxLimit=&quot;100&quot;&gt;</div><div class="line">	&lt;!-- auto sharding by id (long) --&gt;</div><div class="line">	&lt;table name=&quot;travelrecord&quot; dataNode=&quot;dn1,dn2,dn3&quot; rule=&quot;auto-sharding-long&quot; /&gt;</div><div class="line"></div><div class="line">	&lt;!-- global table is auto cloned to all defined data nodes ,so can join</div><div class="line">		with any table whose sharding node is in the same data node --&gt;</div><div class="line">	&lt;table name=&quot;company&quot; primaryKey=&quot;ID&quot; type=&quot;global&quot; dataNode=&quot;dn1,dn2,dn3&quot; /&gt;</div><div class="line">	&lt;table name=&quot;goods&quot; primaryKey=&quot;ID&quot; type=&quot;global&quot; dataNode=&quot;dn1,dn2&quot; /&gt;</div><div class="line">	&lt;!-- random sharding using mod sharind rule --&gt;</div><div class="line">	&lt;table name=&quot;hotnews&quot; primaryKey=&quot;ID&quot; autoIncrement=&quot;true&quot; dataNode=&quot;dn1,dn2,dn3&quot;</div><div class="line">		   rule=&quot;mod-long&quot; /&gt;</div><div class="line">	&lt;!-- &lt;table name=&quot;dual&quot; primaryKey=&quot;ID&quot; dataNode=&quot;dnx,dnoracle2&quot; type=&quot;global&quot;</div><div class="line">		needAddLimit=&quot;false&quot;/&gt; &lt;table name=&quot;worker&quot; primaryKey=&quot;ID&quot; dataNode=&quot;jdbc_dn1,jdbc_dn2,jdbc_dn3&quot;</div><div class="line">		rule=&quot;mod-long&quot; /&gt; --&gt;</div><div class="line">	&lt;table name=&quot;employee&quot; primaryKey=&quot;ID&quot; dataNode=&quot;dn1,dn2&quot;</div><div class="line">		   rule=&quot;sharding-by-intfile&quot; /&gt;</div><div class="line">	&lt;table name=&quot;customer&quot; primaryKey=&quot;ID&quot; dataNode=&quot;dn1,dn2&quot;</div><div class="line">		   rule=&quot;sharding-by-intfile&quot;&gt;</div><div class="line">		&lt;childTable name=&quot;orders&quot; primaryKey=&quot;ID&quot; joinKey=&quot;customer_id&quot;</div><div class="line">					parentKey=&quot;id&quot;&gt;</div><div class="line">			&lt;childTable name=&quot;order_items&quot; joinKey=&quot;order_id&quot;</div><div class="line">						parentKey=&quot;id&quot; /&gt;</div><div class="line">		&lt;/childTable&gt;</div><div class="line">		&lt;childTable name=&quot;customer_addr&quot; primaryKey=&quot;ID&quot; joinKey=&quot;customer_id&quot;</div><div class="line">					parentKey=&quot;id&quot; /&gt;</div><div class="line">	&lt;/table&gt;</div><div class="line">	&lt;!-- &lt;table name=&quot;oc_call&quot; primaryKey=&quot;ID&quot; dataNode=&quot;dn1$0-743&quot; rule=&quot;latest-month-calldate&quot;</div><div class="line">		/&gt; --&gt;</div><div class="line">&lt;/schema&gt;</div></pre></td></tr></table></figure>
<h4 id="修改37-45行-usr-mycat-mycat-conf-wrapper-conf。设置java虚拟机内存。"><a href="#修改37-45行-usr-mycat-mycat-conf-wrapper-conf。设置java虚拟机内存。" class="headerlink" title="修改37-45行 /usr/mycat/mycat/conf/wrapper.conf。设置java虚拟机内存。"></a>修改37-45行 /usr/mycat/mycat/conf/wrapper.conf。设置java虚拟机内存。</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"># Initial Java Heap Size (in MB)</div><div class="line">wrapper.java.initmemory=3</div><div class="line"></div><div class="line"># Maximum Java Heap Size (in MB)</div><div class="line">wrapper.java.maxmemory=64</div></pre></td></tr></table></figure>
<h4 id="在schema-xml往下修改。43-55行。数据源地址dataHost。这些就是我们的数据源，mycat把逻辑表的数据，读写都来源于我们配置地址。其中"><a href="#在schema-xml往下修改。43-55行。数据源地址dataHost。这些就是我们的数据源，mycat把逻辑表的数据，读写都来源于我们配置地址。其中" class="headerlink" title="在schema.xml往下修改。43-55行。数据源地址dataHost。这些就是我们的数据源，mycat把逻辑表的数据，读写都来源于我们配置地址。其中"></a>在schema.xml往下修改。43-55行。数据源地址dataHost。这些就是我们的数据源，mycat把逻辑表的数据，读写都来源于我们配置地址。其中</h4><p>writeHost写入源。设置多个，默认也只用第一个。readHost是读服务器。heartbeat是我们检测数据库是否正常运行的。</p>
<p>在这里 mycat 有两种配置方式。</p>
<p>分别是两个writeHost和一个writeHost一个readHost</p>
<p>第一种如果写入失败，还是可读。</p>
<p>第二种如果写入失败，不可读。</p>
<p>我们采用安全稳妥的方式。一个writeHost一个readHost</p>
<pre><code>我的配置为

&lt;dataHost name=&quot;localhost1&quot; maxCon=&quot;1000&quot; minCon=&quot;20&quot; balance=&quot;1&quot;
          writeType=&quot;0&quot; dbType=&quot;mysql&quot; dbDriver=&quot;native&quot; switchType=&quot;2&quot;  slaveThreshold=&quot;100&quot;&gt;

    &lt;heartbeat&gt;show slave status&lt;/heartbeat&gt;
    &lt;!-- can have multi write hosts --&gt;
    &lt;writeHost host=&quot;hostM1&quot; url=&quot;115.159.124.18:32768&quot; user=&quot;root&quot;    password=&quot;mysql&quot;&gt;
        &lt;!-- can have multi read hosts --&gt;
        &lt;readHost host=&quot;hostS1&quot; url=&quot;115.159.124.18:32769&quot; user=&quot;root&quot;    password=&quot;mysql&quot; /&gt;

    &lt;/writeHost&gt;

&lt;/dataHost&gt;
</code></pre><p>hostM1和hostS1分别对应我们创建的两个docker容器的对外端口。</p>
<h4 id="修改-usr-mycat-mycat-conf-log4j2-xml-这个是配置日志文件的，我们打开debug方便我们学习。修改第25行info为debug"><a href="#修改-usr-mycat-mycat-conf-log4j2-xml-这个是配置日志文件的，我们打开debug方便我们学习。修改第25行info为debug" class="headerlink" title="修改/usr/mycat/mycat/conf/log4j2.xml  这个是配置日志文件的，我们打开debug方便我们学习。修改第25行info为debug"></a>修改/usr/mycat/mycat/conf/log4j2.xml  这个是配置日志文件的，我们打开debug方便我们学习。修改第25行info为debug</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&lt;asyncRoot level=&quot;debug&quot; includeLocation=&quot;true&quot;&gt;</div><div class="line"></div><div class="line">     &lt;AppenderRef ref=&quot;Console&quot; /&gt;</div><div class="line">     &lt;AppenderRef ref=&quot;RollingFile&quot;/&gt;</div><div class="line"></div><div class="line"> &lt;/asyncRoot&gt;</div></pre></td></tr></table></figure>
<h4 id="构建镜像"><a href="#构建镜像" class="headerlink" title="构建镜像"></a>构建镜像</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">docker build -t sunhao/mycat:1.6  . 别忘了最后面的圆点</div></pre></td></tr></table></figure>
<h4 id="运行创建容器"><a href="#运行创建容器" class="headerlink" title="运行创建容器"></a>运行创建容器</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">docker  run  --name sunhaomycat  -d -p 8066:8066 -p 9066:9066 sunhao/mycat:1.6</div></pre></td></tr></table></figure>
<h3 id="就那么简单。我们的mycat已经搭建成功了。测试下吧打开4个终端"><a href="#就那么简单。我们的mycat已经搭建成功了。测试下吧打开4个终端" class="headerlink" title="就那么简单。我们的mycat已经搭建成功了。测试下吧打开4个终端"></a>就那么简单。我们的mycat已经搭建成功了。测试下吧打开4个终端</h3><p>1个宿主，1个mysql主，1个mysql从，1个用来看mycat日志。</p>
<h4 id="宿主环境操作"><a href="#宿主环境操作" class="headerlink" title="宿主环境操作"></a>宿主环境操作</h4><p>在宿主终端上，安装mysql。并且连接我们的mycat。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[root@VM_128_230_centos mycat]# mysql -uroot -p123456 -h115.159.124.18 -P8066</div><div class="line">Welcome to the MariaDB monitor.  Commands end with ; or \g.</div><div class="line">Your MySQL connection id is 8</div><div class="line">Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)</div><div class="line"></div><div class="line">Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.</div><div class="line"></div><div class="line">Type &apos;help;&apos; or &apos;\h&apos; for help. Type &apos;\c&apos; to clear the current input statement.</div><div class="line"></div><div class="line">MySQL [(none)]&gt;</div></pre></td></tr></table></figure>
<p>完美，Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server 出现这，说明mycat运行了。</p>
<p>进行简单的操作。</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div></pre></td><td class="code"><pre><div class="line">Database changed</div><div class="line">MySQL [TESTDB]&gt; show databases;</div><div class="line">+----------+</div><div class="line">| DATABASE |</div><div class="line">+----------+</div><div class="line">| TESTDB   |</div><div class="line">+----------+</div><div class="line">1 row in set (0.00 sec)</div><div class="line"></div><div class="line">MySQL [TESTDB]&gt; show tables;</div><div class="line">+------------------+</div><div class="line">| Tables in TESTDB |</div><div class="line">+------------------+</div><div class="line">| company          |</div><div class="line">| customer         |</div><div class="line">| customer_addr    |</div><div class="line">| employee         |</div><div class="line">| goods            |</div><div class="line">| hotnews          |</div><div class="line">| orders           |</div><div class="line">| order_items      |</div><div class="line">| travelrecord     |</div><div class="line">+------------------+</div><div class="line">9 rows in set (0.00 sec)</div><div class="line"></div><div class="line">MySQL [TESTDB]&gt;</div></pre></td></tr></table></figure>
<h4 id="测试下写入"><a href="#测试下写入" class="headerlink" title="测试下写入"></a>测试下写入</h4><figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">MySQL [TESTDB]&gt; create table travelrecord (id bigint not null primary key,user_id varchar(100),traveldate DATE, fee decimal,days int);</div><div class="line">ERROR 1105 (HY000): Table 'travelrecord' already exists</div><div class="line">MySQL [TESTDB]&gt; insert into travelrecord(id,user_id,traveldate,fee,days)  values(1,@@hostname,20170707,100,10);</div><div class="line">Query OK, 1 row affected (0.01 sec)</div><div class="line"></div><div class="line">MySQL [TESTDB]&gt; </div><div class="line">MySQL [TESTDB]&gt; insert into travelrecord(id,user_id,traveldate,fee,days)  values(10000001,@@hostname,20170707,100,10);</div><div class="line">Query OK, 1 row affected (0.00 sec)</div></pre></td></tr></table></figure>
<p>分别进入mysql主和mysql从可以看到。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div></pre></td><td class="code"><pre><div class="line">MySQL [data2]&gt; use data3                  </div><div class="line">Reading table information for completion of table and column names</div><div class="line">You can turn off this feature to get a quicker startup with -A</div><div class="line"></div><div class="line">Database changed</div><div class="line">MySQL [data3]&gt; select * from travelrecord;</div><div class="line">+----------+--------------+------------+------+------+</div><div class="line">| id       | user_id      | traveldate | fee  | days |</div><div class="line">+----------+--------------+------------+------+------+</div><div class="line">| 10000001 | 980e5ea48152 | 2017-07-07 |  100 |   10 |</div><div class="line">+----------+--------------+------------+------+------+</div><div class="line">1 row in set (0.00 sec)</div><div class="line"></div><div class="line">MySQL [data3]&gt; use data1;                 </div><div class="line">Reading table information for completion of table and column names</div><div class="line">You can turn off this feature to get a quicker startup with -A</div><div class="line"></div><div class="line">Database changed</div><div class="line">MySQL [data1]&gt; select * from travelrecord;</div><div class="line">+----+--------------+------------+------+------+</div><div class="line">| id | user_id      | traveldate | fee  | days |</div><div class="line">+----+--------------+------------+------+------+</div><div class="line">|  1 | 980e5ea48152 | 2017-07-07 |  100 |   10 |</div><div class="line">+----+--------------+------------+------+------+</div><div class="line">1 row in set (0.00 sec)</div><div class="line"></div><div class="line">MySQL [data1]&gt;</div></pre></td></tr></table></figure>
<h4 id="测试读取分离"><a href="#测试读取分离" class="headerlink" title="测试读取分离"></a>测试读取分离</h4><p>打开一个终端，用</p>
<pre><code>docker exec -it 61e74eee274d9d0f0404a572dec1d14c8b03dfd480e13d3c96fa04c534df0556  bash
</code></pre><p>进入我们的mycat容器</p>
<p>其中61e74为你的mycat容器</p>
<p>这个就是我们的日志终端</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">root@61e74eee274d:/var/local/mycat/logs# ls</div><div class="line">2017-07  mycat.log  mycat.pid  wrapper.log</div><div class="line">root@61e74eee274d:/var/local/mycat/logs# tail -f  mycat.log</div></pre></td></tr></table></figure>
<p>在宿主环境mycat下</p>
<p>输入</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">MySQL [TESTDB]&gt; select * from travelrecord ;</div><div class="line">ERROR 2006 (HY000): MySQL server has gone away</div><div class="line">No connection. Trying to reconnect...</div><div class="line">Connection id:    9</div><div class="line">Current database: TESTDB</div><div class="line"></div><div class="line">+----------+--------------+------------+------+------+</div><div class="line">| id       | user_id      | traveldate | fee  | days |</div><div class="line">+----------+--------------+------------+------+------+</div><div class="line">|        1 | 980e5ea48152 | 2017-07-07 |  100 |   10 |</div><div class="line">| 10000001 | 980e5ea48152 | 2017-07-07 |  100 |   10 |</div><div class="line">+----------+--------------+------------+------+------+</div><div class="line">2 rows in set (0.02 sec)</div></pre></td></tr></table></figure>
<p>然后切回我们的日志终端，按ctrl+c中断。</p>
<p>然后输入cat tail 进行查看，很长在最后面找个空白的大坑（自己体会）慢慢找。</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div></pre></td><td class="code"><pre><div class="line">017-07-07 06:28:16.863 DEBUG [$_NIOREACTOR-5-RW] (io.mycat.backend.datasource.PhysicalDatasource.releaseChannel(PhysicalDatasource.java:442)) - <span class="keyword">release</span> channel MySQLConnection [<span class="keyword">id</span>=<span class="number">5</span>, lastTime=<span class="number">1499408896859</span>, <span class="keyword">user</span>=root, <span class="keyword">schema</span>=data3, <span class="keyword">old</span> shema=data3, borrowed=<span class="literal">true</span>, fromSlaveDB=<span class="literal">false</span>, threadId=<span class="number">527</span>, <span class="keyword">charset</span>=latin1, txIsolation=<span class="number">3</span>, autocommit=<span class="literal">true</span>, attachment=<span class="literal">null</span>, respHandler=<span class="literal">null</span>, host=<span class="number">115.159</span><span class="number">.184</span><span class="number">.18</span>, port=<span class="number">32774</span>, statusSync=<span class="literal">null</span>, writeQueue=<span class="number">0</span>, modifiedSQLExecuted=<span class="literal">false</span>]</div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">16.864</span> DEBUG [$_NIOREACTOR<span class="number">-3</span>-RW] (io.mycat.backend.datasource.PhysicalDatasource.releaseChannel(PhysicalDatasource.java:<span class="number">442</span>)) - <span class="keyword">release</span> channel MySQLConnection [<span class="keyword">id</span>=<span class="number">33</span>, lastTime=<span class="number">1499408896859</span>, <span class="keyword">user</span>=root, <span class="keyword">schema</span>=data3, <span class="keyword">old</span> shema=data3, borrowed=<span class="literal">true</span>, fromSlaveDB=<span class="literal">true</span>, threadId=<span class="number">108</span>, <span class="keyword">charset</span>=latin1, txIsolation=<span class="number">3</span>, autocommit=<span class="literal">true</span>, attachment=<span class="literal">null</span>, respHandler=<span class="literal">null</span>, host=<span class="number">115.159</span><span class="number">.184</span><span class="number">.18</span>, port=<span class="number">32770</span>, statusSync=<span class="literal">null</span>, writeQueue=<span class="number">0</span>, modifiedSQLExecuted=<span class="literal">false</span>]</div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.473</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.net.FrontendConnection.query(FrontendConnection.java:<span class="number">288</span>)) - ServerConnection [<span class="keyword">id</span>=<span class="number">2</span>, <span class="keyword">schema</span>=TESTDB, host=<span class="number">115.159</span><span class="number">.184</span><span class="number">.18</span>, <span class="keyword">user</span>=root,txIsolation=<span class="number">3</span>, autocommit=<span class="literal">true</span>, <span class="keyword">schema</span>=TESTDB] <span class="keyword">select</span> * <span class="keyword">from</span> travelrecord</div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.474</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.server.ServerQueryHandler.query(ServerQueryHandler.java:<span class="number">57</span>)) - ServerConnection [<span class="keyword">id</span>=<span class="number">2</span>, <span class="keyword">schema</span>=TESTDB, host=<span class="number">115.159</span><span class="number">.184</span><span class="number">.18</span>, <span class="keyword">user</span>=root,txIsolation=<span class="number">3</span>, autocommit=<span class="literal">true</span>, <span class="keyword">schema</span>=TESTDB]<span class="keyword">select</span> * <span class="keyword">from</span> travelrecord</div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.474</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.cache.impl.EnchachePool.get(EnchachePool.java:<span class="number">71</span>)) - SQLRouteCache hit <span class="keyword">cache</span> ,<span class="keyword">key</span>:TESTDBselect * <span class="keyword">from</span> travelrecord</div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.474</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.server.NonBlockingSession.execute(NonBlockingSession.java:<span class="number">110</span>)) - ServerConnection [<span class="keyword">id</span>=<span class="number">2</span>, <span class="keyword">schema</span>=TESTDB, host=<span class="number">115.159</span><span class="number">.184</span><span class="number">.18</span>, <span class="keyword">user</span>=root,txIsolation=<span class="number">3</span>, autocommit=<span class="literal">true</span>, <span class="keyword">schema</span>=TESTDB]<span class="keyword">select</span> * <span class="keyword">from</span> travelrecord, route=&#123;</div><div class="line">   <span class="number">1</span> -&gt; dn1&#123;<span class="keyword">SELECT</span> *</div><div class="line"><span class="keyword">FROM</span> travelrecord</div><div class="line"><span class="keyword">LIMIT</span> <span class="number">100</span>&#125;</div><div class="line">   <span class="number">2</span> -&gt; dn2&#123;<span class="keyword">SELECT</span> *</div><div class="line"><span class="keyword">FROM</span> travelrecord</div><div class="line"><span class="keyword">LIMIT</span> <span class="number">100</span>&#125;</div><div class="line">   <span class="number">3</span> -&gt; dn3&#123;<span class="keyword">SELECT</span> *</div><div class="line"><span class="keyword">FROM</span> travelrecord</div><div class="line"><span class="keyword">LIMIT</span> <span class="number">100</span>&#125;</div><div class="line">&#125; rrs </div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.474</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.&lt;init&gt;(MultiNodeQueryHandler.java:<span class="number">101</span>)) - <span class="keyword">execute</span> mutinode <span class="keyword">query</span> <span class="keyword">select</span> * <span class="keyword">from</span> travelrecord</div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.474</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.&lt;init&gt;(MultiNodeQueryHandler.java:<span class="number">137</span>)) - has <span class="keyword">data</span> <span class="keyword">merge</span> logic </div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.474</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:<span class="number">170</span>)) - rrs.getRunOnSlave()-<span class="literal">null</span></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.474</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:<span class="number">180</span>)) - node.getRunOnSlave()<span class="number">1</span>-<span class="literal">null</span></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.474</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:<span class="number">182</span>)) - node.getRunOnSlave()<span class="number">2</span>-<span class="literal">null</span></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.474</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:<span class="number">96</span>)) - rrs.getRunOnSlave() <span class="literal">null</span></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.475</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:<span class="number">127</span>)) - rrs.getRunOnSlave() <span class="literal">null</span></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.475</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.datasource.PhysicalDBPool.getRWBanlanceCon(PhysicalDBPool.java:<span class="number">456</span>)) - <span class="keyword">select</span> <span class="keyword">read</span> <span class="keyword">source</span> hostS1 <span class="keyword">for</span> dataHost:localhost1</div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.475</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:<span class="number">180</span>)) - node.getRunOnSlave()<span class="number">1</span>-<span class="literal">null</span></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.475</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:<span class="number">182</span>)) - node.getRunOnSlave()<span class="number">2</span>-<span class="literal">null</span></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.475</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:<span class="number">96</span>)) - rrs.getRunOnSlave() <span class="literal">null</span></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.475</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:<span class="number">127</span>)) - rrs.getRunOnSlave() <span class="literal">null</span></div><div class="line"></div><div class="line"></div><div class="line">就是这了我们可以看到<span class="keyword">select</span> <span class="keyword">read</span> <span class="keyword">source</span> hostS1 <span class="keyword">for</span> dataHost:localhost1来至哪个服务器</div><div class="line"></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.475</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.datasource.PhysicalDBPool.getRWBanlanceCon(PhysicalDBPool.java:<span class="number">456</span>)) - <span class="keyword">select</span> <span class="keyword">read</span> <span class="keyword">source</span> hostS1 <span class="keyword">for</span> dataHost:localhost1</div><div class="line"></div><div class="line"></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.475</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:<span class="number">180</span>)) - node.getRunOnSlave()<span class="number">1</span>-<span class="literal">null</span></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.475</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:<span class="number">182</span>)) - node.getRunOnSlave()<span class="number">2</span>-<span class="literal">null</span></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.475</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:<span class="number">96</span>)) - rrs.getRunOnSlave() <span class="literal">null</span></div><div class="line"><span class="number">2017</span><span class="number">-07</span><span class="number">-07</span> <span class="number">06</span>:<span class="number">28</span>:<span class="number">24.476</span> DEBUG [$_NIOREACTOR<span class="number">-29</span>-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection</div></pre></td></tr></table></figure>
<h4 id="如果配置不小心错了，可以用docker-cp-复制到镜像里，然后重启镜像"><a href="#如果配置不小心错了，可以用docker-cp-复制到镜像里，然后重启镜像" class="headerlink" title="如果配置不小心错了，可以用docker cp 复制到镜像里，然后重启镜像"></a>如果配置不小心错了，可以用docker cp 复制到镜像里，然后重启镜像</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">docker cp /usr/mycat/mycat/conf 61e74eee274d9d0f0404a572dec1d14c8b03dfd480e13d3c96fa04c534df0556:/var/local/mycat/conf</div><div class="line"></div><div class="line">docker restart 61e74eee274d9d0f0404a572dec1d14c8b03dfd480e13d3c96fa04c534df0556</div></pre></td></tr></table></figure>
<h3 id="总结，如果运行中docker过会就掉了，说明配置出错，会运行有问题。请仔细检查配置。docker用来单机测试堪称完美，对于资源不足，环境变化大的。方便太多。推荐大家多做练习。"><a href="#总结，如果运行中docker过会就掉了，说明配置出错，会运行有问题。请仔细检查配置。docker用来单机测试堪称完美，对于资源不足，环境变化大的。方便太多。推荐大家多做练习。" class="headerlink" title="总结，如果运行中docker过会就掉了，说明配置出错，会运行有问题。请仔细检查配置。docker用来单机测试堪称完美，对于资源不足，环境变化大的。方便太多。推荐大家多做练习。"></a>总结，如果运行中docker过会就掉了，说明配置出错，会运行有问题。请仔细检查配置。docker用来单机测试堪称完美，对于资源不足，环境变化大的。方便太多。推荐大家多做练习。</h3>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;利用docker实现mysql主从同步-读写分离&quot;&gt;&lt;a href=&quot;#利用docker实现mysql主从同步-读写分离&quot; class=&quot;headerlink&quot; title=&quot;利用docker实现mysql主从同步/读写分离&quot;&gt;&lt;/a&gt;利用docker实现mysql主从同步/读写分离&lt;/h2&gt;&lt;p&gt;为了保证数据的完整和安全，mysql设计了主从同步，一个挂掉还可以用另个。最近重构论坛，想来改成主从吧。担心失误，就先拿docker练练手。&lt;br&gt;有错误或者不理解的地方，可以联系本人邮箱sunhaokk@qq.com。&lt;/p&gt;
&lt;p&gt;通过本文实际你会操作到。&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;mysql的主从同步&lt;/li&gt;
&lt;li&gt;docker镜像和容器的创建&lt;/li&gt;
&lt;li&gt;docker容器间的数据传递&lt;/li&gt;
&lt;li&gt;mycat入门&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;以下需要大于100的智商和mysql基础docker基础，linux基础。&lt;/p&gt;
&lt;p&gt;没有也没事，就是看着会有点吃力。&lt;/p&gt;
&lt;p&gt;环境是centos，mycat是1.6.docker是1.12.6&lt;/p&gt;
&lt;h3 id=&quot;下载mysql镜像。&quot;&gt;&lt;a href=&quot;#下载mysql镜像。&quot; class=&quot;headerlink&quot; title=&quot;下载mysql镜像。&quot;&gt;&lt;/a&gt;下载mysql镜像。&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;docker pull mysql


ps:如果下载太慢，请添加腾讯源,依次执行
&lt;/code&gt;&lt;/pre&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;echo &amp;quot;OPTIONS=&amp;apos;--registry-mirror=https://mirror.ccs.tencentyun.com&amp;apos;&amp;quot; &amp;gt;&amp;gt; /etc/sysconfig/docker&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;systemctl daemon-reload&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;service docker restart&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;或者直接去阿里仓库下&lt;a href=&quot;https://dev.aliyun.com/search.html把上面的--registry-mirror=https://mirror.ccs.tencentyun.com换成你的专属源就可以&quot; target=&quot;_blank&quot; rel=&quot;external&quot;&gt;https://dev.aliyun.com/search.html把上面的--registry-mirror=https://mirror.ccs.tencentyun.com换成你的专属源就可以&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;下载完输入&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker images
&lt;/code&gt;&lt;/pre&gt;&lt;figure class=&quot;highlight plain&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;docker.io/mysql             latest              44a8e1a5c0b2        8 days ago          407 MB&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;h3 id=&quot;利用mysql镜像，创建用于主从同步的两个新镜像。&quot;&gt;&lt;a href=&quot;#利用mysql镜像，创建用于主从同步的两个新镜像。&quot; class=&quot;headerlink&quot; title=&quot;利用mysql镜像，创建用于主从同步的两个新镜像。&quot;&gt;&lt;/a&gt;利用mysql镜像，创建用于主从同步的两个新镜像。&lt;/h3&gt;&lt;p&gt;我们当前所在的服务器叫&lt;strong&gt;宿主服务器&lt;/strong&gt;，&lt;/p&gt;
&lt;p&gt;我们要利用docker 虚拟两个docker容器服务器，一个主服务器，一个从服务器。&lt;/p&gt;
    
    </summary>
    
      <category term="mysql" scheme="http://sunhao.win/categories/mysql/"/>
    
    
      <category term="docker" scheme="http://sunhao.win/tags/docker/"/>
    
  </entry>
  
  <entry>
    <title>gulp教程之gulp中文API</title>
    <link href="http://sunhao.win/articles/gulp-config-src.html"/>
    <id>http://sunhao.win/articles/gulp-config-src.html</id>
    <published>2017-06-26T06:50:52.000Z</published>
    <updated>2017-06-26T07:34:31.613Z</updated>
    
    <content type="html"><![CDATA[<blockquote>
<p>原文链接:<a href="http://www.ydcss.com/archives/424" target="_blank" rel="external">http://www.ydcss.com/archives/424</a></p>
</blockquote>
<h2 id="gulp-src-globs-options"><a href="#gulp-src-globs-options" class="headerlink" title="gulp.src(globs[, options])"></a>gulp.src(globs[, options])</h2><h3 id="说明：src方法是指定需要处理的源文件的路径，gulp借鉴了Unix操作系统的管道（pipe）思想，前一级的输出，直接变成后一级的输入，gulp-src返回当前文件流至可用插件；"><a href="#说明：src方法是指定需要处理的源文件的路径，gulp借鉴了Unix操作系统的管道（pipe）思想，前一级的输出，直接变成后一级的输入，gulp-src返回当前文件流至可用插件；" class="headerlink" title="说明：src方法是指定需要处理的源文件的路径，gulp借鉴了Unix操作系统的管道（pipe）思想，前一级的输出，直接变成后一级的输入，gulp.src返回当前文件流至可用插件；"></a>说明：src方法是指定需要处理的源文件的路径，gulp借鉴了Unix操作系统的管道（pipe）思想，前一级的输出，直接变成后一级的输入，gulp.src返回当前文件流至可用插件；</h3><h3 id="globs：-需要处理的源文件匹配符路径。类型-必填-：String-or-StringArray；"><a href="#globs：-需要处理的源文件匹配符路径。类型-必填-：String-or-StringArray；" class="headerlink" title="globs：  需要处理的源文件匹配符路径。类型(必填)：String or StringArray；"></a>globs：  需要处理的源文件匹配符路径。类型(必填)：String or StringArray；</h3><p>通配符路径匹配示例：</p>
<h4 id="“src-a-js”：指定具体文件；"><a href="#“src-a-js”：指定具体文件；" class="headerlink" title="“src/a.js”：指定具体文件；"></a>“src/a.js”：指定具体文件；</h4><h4 id="“”：匹配所有文件-例：src-js-包含src下的所有js文件-；"><a href="#“”：匹配所有文件-例：src-js-包含src下的所有js文件-；" class="headerlink" title="“”：匹配所有文件    例：src/.js(包含src下的所有js文件)；"></a>“<em>”：匹配所有文件    例：src/</em>.js(包含src下的所有js文件)；</h4><h4 id="“”：匹配0个或多个子文件夹-例：src-js-包含src的0个或多个子文件夹下的js文件-；"><a href="#“”：匹配0个或多个子文件夹-例：src-js-包含src的0个或多个子文件夹下的js文件-；" class="headerlink" title="“”：匹配0个或多个子文件夹    例：src//*.js(包含src的0个或多个子文件夹下的js文件)；"></a>“<strong>”：匹配0个或多个子文件夹    例：src/</strong>/*.js(包含src的0个或多个子文件夹下的js文件)；</h4><h4 id="“-”：匹配多个属性-例：src-a-b-js-包含a-js和b-js文件-src-jpg-png-gif-src下的所有jpg-png-gif文件-；"><a href="#“-”：匹配多个属性-例：src-a-b-js-包含a-js和b-js文件-src-jpg-png-gif-src下的所有jpg-png-gif文件-；" class="headerlink" title="“{}”：匹配多个属性    例：src/{a,b}.js(包含a.js和b.js文件)  src/*.{jpg,png,gif}(src下的所有jpg/png/gif文件)；"></a>“{}”：匹配多个属性    例：src/{a,b}.js(包含a.js和b.js文件)  src/*.{jpg,png,gif}(src下的所有jpg/png/gif文件)；</h4><h4 id="“-”：排除文件-例：-src-a-js-不包含src下的a-js文件-；"><a href="#“-”：排除文件-例：-src-a-js-不包含src下的a-js文件-；" class="headerlink" title="“!”：排除文件    例：!src/a.js(不包含src下的a.js文件)；"></a>“!”：排除文件    例：!src/a.js(不包含src下的a.js文件)；</h4><a id="more"></a>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"></div><div class="line"><span class="keyword">var</span> gulp = <span class="built_in">require</span>(<span class="string">'gulp'</span>),</div><div class="line">    less = <span class="built_in">require</span>(<span class="string">'gulp-less'</span>);</div><div class="line"> </div><div class="line">gulp.task(<span class="string">'testLess'</span>, <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</div><div class="line">    <span class="comment">//gulp.src('less/test/style.less')</span></div><div class="line">    gulp.src([<span class="string">'less/**/*.less'</span>,<span class="string">'!less/&#123;extend,page&#125;/*.less'</span>])</div><div class="line">        .pipe(less())</div><div class="line">        .pipe(gulp.dest(<span class="string">'./css'</span>));</div><div class="line">&#125;);</div></pre></td></tr></table></figure>
<h3 id="options：-类型-可选-：Object，有3个属性buffer、read、base；"><a href="#options：-类型-可选-：Object，有3个属性buffer、read、base；" class="headerlink" title="options：  类型(可选)：Object，有3个属性buffer、read、base；"></a>options：  类型(可选)：Object，有3个属性buffer、read、base；</h3><h4 id="options-buffer：-类型：Boolean-默认：true-设置为false，将返回file-content的流并且不缓冲文件，处理大文件时非常有用；"><a href="#options-buffer：-类型：Boolean-默认：true-设置为false，将返回file-content的流并且不缓冲文件，处理大文件时非常有用；" class="headerlink" title="options.buffer：  类型：Boolean  默认：true 设置为false，将返回file.content的流并且不缓冲文件，处理大文件时非常有用；"></a>options.buffer：  类型：Boolean  默认：true 设置为false，将返回file.content的流并且不缓冲文件，处理大文件时非常有用；</h4><h4 id="options-read：-类型：Boolean-默认：true-设置false，将不执行读取文件操作，返回null；"><a href="#options-read：-类型：Boolean-默认：true-设置false，将不执行读取文件操作，返回null；" class="headerlink" title="options.read：  类型：Boolean  默认：true 设置false，将不执行读取文件操作，返回null；"></a>options.read：  类型：Boolean  默认：true 设置false，将不执行读取文件操作，返回null；</h4><h4 id="options-base：-类型：String-设置输出路径以某个路径的某个组成部分为基础向后拼接，具体看下面示例："><a href="#options-base：-类型：String-设置输出路径以某个路径的某个组成部分为基础向后拼接，具体看下面示例：" class="headerlink" title="options.base：  类型：String  设置输出路径以某个路径的某个组成部分为基础向后拼接，具体看下面示例："></a>options.base：  类型：String  设置输出路径以某个路径的某个组成部分为基础向后拼接，具体看下面示例：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">gulp.src(&apos;client/js/**/*.js&apos;) </div><div class="line">  .pipe(minify())</div><div class="line">  .pipe(gulp.dest(&apos;build&apos;));  // Writes &apos;build/somedir/somefile.js&apos;</div><div class="line"> </div><div class="line">gulp.src(&apos;client/js/**/*.js&apos;, &#123; base: &apos;client&apos; &#125;)</div><div class="line">  .pipe(minify())</div><div class="line">  .pipe(gulp.dest(&apos;build&apos;));  // Writes &apos;build/js/somedir/somefile.js&apos;</div></pre></td></tr></table></figure>
<h2 id="gulp-dest-path-options"><a href="#gulp-dest-path-options" class="headerlink" title="gulp.dest(path[, options])"></a>gulp.dest(path[, options])</h2><h3 id="说明：dest方法是指定处理完后文件输出的路径；"><a href="#说明：dest方法是指定处理完后文件输出的路径；" class="headerlink" title="说明：dest方法是指定处理完后文件输出的路径；"></a>说明：dest方法是指定处理完后文件输出的路径；</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">gulp.src(&apos;./client/templates/*.jade&apos;)</div><div class="line">  .pipe(jade())</div><div class="line">  .pipe(gulp.dest(&apos;./build/templates&apos;))</div><div class="line">  .pipe(minify())</div><div class="line">  .pipe(gulp.dest(&apos;./build/minified_templates&apos;));</div></pre></td></tr></table></figure>
<h3 id="path：-类型-必填-：String-or-Function-指定文件输出路径，或者定义函数返回文件输出路径亦可；"><a href="#path：-类型-必填-：String-or-Function-指定文件输出路径，或者定义函数返回文件输出路径亦可；" class="headerlink" title="path：  类型(必填)：String or Function 指定文件输出路径，或者定义函数返回文件输出路径亦可；"></a>path：  类型(必填)：String or Function 指定文件输出路径，或者定义函数返回文件输出路径亦可；</h3><h3 id="options：-类型-可选-：Object，有2个属性cwd、mode；"><a href="#options：-类型-可选-：Object，有2个属性cwd、mode；" class="headerlink" title="options：  类型(可选)：Object，有2个属性cwd、mode；"></a>options：  类型(可选)：Object，有2个属性cwd、mode；</h3><h3 id="options-cwd：-类型：String-默认：process-cwd-：前脚本的工作目录的路径-当文件输出路径为相对路径将会用到；"><a href="#options-cwd：-类型：String-默认：process-cwd-：前脚本的工作目录的路径-当文件输出路径为相对路径将会用到；" class="headerlink" title="options.cwd：  类型：String  默认：process.cwd()：前脚本的工作目录的路径 当文件输出路径为相对路径将会用到；"></a>options.cwd：  类型：String  默认：process.cwd()：前脚本的工作目录的路径 当文件输出路径为相对路径将会用到；</h3><h3 id="options-mode：-类型：String-默认：0777-指定被创建文件夹的权限；"><a href="#options-mode：-类型：String-默认：0777-指定被创建文件夹的权限；" class="headerlink" title="options.mode：  类型：String  默认：0777 指定被创建文件夹的权限；"></a>options.mode：  类型：String  默认：0777 指定被创建文件夹的权限；</h3><h2 id="gulp-task-name-deps-fn"><a href="#gulp-task-name-deps-fn" class="headerlink" title="gulp.task(name[, deps], fn)"></a>gulp.task(name[, deps], fn)</h2><h3 id="说明：task定义一个gulp任务；"><a href="#说明：task定义一个gulp任务；" class="headerlink" title="说明：task定义一个gulp任务；"></a>说明：task定义一个gulp任务；</h3><h3 id="name：-类型-必填-：String-指定任务的名称（不应该有空格）；"><a href="#name：-类型-必填-：String-指定任务的名称（不应该有空格）；" class="headerlink" title="name：  类型(必填)：String 指定任务的名称（不应该有空格）；"></a>name：  类型(必填)：String 指定任务的名称（不应该有空格）；</h3><h3 id="deps：-类型-可选-：StringArray，该任务依赖的任务（注意：被依赖的任务需要返回当前任务的事件流，请参看下面示例）；"><a href="#deps：-类型-可选-：StringArray，该任务依赖的任务（注意：被依赖的任务需要返回当前任务的事件流，请参看下面示例）；" class="headerlink" title="deps：  类型(可选)：StringArray，该任务依赖的任务（注意：被依赖的任务需要返回当前任务的事件流，请参看下面示例）；"></a>deps：  类型(可选)：StringArray，该任务依赖的任务（注意：被依赖的任务需要返回当前任务的事件流，请参看下面示例）；</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">gulp.task(&apos;testLess&apos;, function () &#123;</div><div class="line">    return gulp.src([&apos;less/style.less&apos;])</div><div class="line">        .pipe(less())</div><div class="line">        .pipe(gulp.dest(&apos;./css&apos;));</div><div class="line">&#125;);</div><div class="line"> </div><div class="line">gulp.task(&apos;minicss&apos;, [&apos;testLess&apos;], function () &#123; //执行完testLess任务后再执行minicss任务</div><div class="line">    gulp.src([&apos;css/*.css&apos;])</div><div class="line">        .pipe(minifyCss())</div><div class="line">        .pipe(gulp.dest(&apos;./dist/css&apos;));</div><div class="line">&#125;);</div></pre></td></tr></table></figure>
<h2 id="fn：-类型-必填-：Function-该任务调用的插件操作；"><a href="#fn：-类型-必填-：Function-该任务调用的插件操作；" class="headerlink" title="fn：  类型(必填)：Function 该任务调用的插件操作；"></a>fn：  类型(必填)：Function 该任务调用的插件操作；</h2><h3 id="gulp-watch-glob-opts-tasks-or-gulp-watch-glob-opts-cb"><a href="#gulp-watch-glob-opts-tasks-or-gulp-watch-glob-opts-cb" class="headerlink" title="gulp.watch(glob [, opts], tasks) or gulp.watch(glob [, opts, cb])"></a>gulp.watch(glob [, opts], tasks) or gulp.watch(glob [, opts, cb])</h3><h3 id="说明：watch方法是用于监听文件变化，文件一修改就会执行指定的任务；"><a href="#说明：watch方法是用于监听文件变化，文件一修改就会执行指定的任务；" class="headerlink" title="说明：watch方法是用于监听文件变化，文件一修改就会执行指定的任务；"></a>说明：watch方法是用于监听文件变化，文件一修改就会执行指定的任务；</h3><h3 id="glob：-需要处理的源文件匹配符路径。类型-必填-：String-or-StringArray；"><a href="#glob：-需要处理的源文件匹配符路径。类型-必填-：String-or-StringArray；" class="headerlink" title="glob：  需要处理的源文件匹配符路径。类型(必填)：String or StringArray；"></a>glob：  需要处理的源文件匹配符路径。类型(必填)：String or StringArray；</h3><h3 id="opts：-类型-可选-：Object-具体参看https-github-com-shama-gaze；"><a href="#opts：-类型-可选-：Object-具体参看https-github-com-shama-gaze；" class="headerlink" title="opts：  类型(可选)：Object 具体参看https://github.com/shama/gaze；"></a>opts：  类型(可选)：Object 具体参看<a href="https://github.com/shama/gaze；" target="_blank" rel="external">https://github.com/shama/gaze；</a></h3><h3 id="tasks：-类型-必填-：StringArray-需要执行的任务的名称数组；"><a href="#tasks：-类型-必填-：StringArray-需要执行的任务的名称数组；" class="headerlink" title="tasks：  类型(必填)：StringArray 需要执行的任务的名称数组；"></a>tasks：  类型(必填)：StringArray 需要执行的任务的名称数组；</h3><h3 id="cb-event-：-类型-可选-：Function-每个文件变化执行的回调函数；"><a href="#cb-event-：-类型-可选-：Function-每个文件变化执行的回调函数；" class="headerlink" title="cb(event)：  类型(可选)：Function 每个文件变化执行的回调函数；"></a>cb(event)：  类型(可选)：Function 每个文件变化执行的回调函数；</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">gulp.task(&apos;watch1&apos;, function () &#123;</div><div class="line">    gulp.watch(&apos;less/**/*.less&apos;, [&apos;testLess&apos;]);</div><div class="line">&#125;);</div><div class="line"> </div><div class="line">gulp.task(&apos;watch2&apos;, function () &#123;</div><div class="line">    gulp.watch(&apos;js/**/*.js&apos;, function (event) &#123;</div><div class="line">        console.log(&apos;File &apos; + event.path + &apos; was &apos; + event.type + &apos;, running tasks...&apos;);</div><div class="line">    &#125;);</div><div class="line">&#125;);</div></pre></td></tr></table></figure>
]]></content>
    
    <summary type="html">
    
      &lt;blockquote&gt;
&lt;p&gt;原文链接:&lt;a href=&quot;http://www.ydcss.com/archives/424&quot; target=&quot;_blank&quot; rel=&quot;external&quot;&gt;http://www.ydcss.com/archives/424&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;gulp-src-globs-options&quot;&gt;&lt;a href=&quot;#gulp-src-globs-options&quot; class=&quot;headerlink&quot; title=&quot;gulp.src(globs[, options])&quot;&gt;&lt;/a&gt;gulp.src(globs[, options])&lt;/h2&gt;&lt;h3 id=&quot;说明：src方法是指定需要处理的源文件的路径，gulp借鉴了Unix操作系统的管道（pipe）思想，前一级的输出，直接变成后一级的输入，gulp-src返回当前文件流至可用插件；&quot;&gt;&lt;a href=&quot;#说明：src方法是指定需要处理的源文件的路径，gulp借鉴了Unix操作系统的管道（pipe）思想，前一级的输出，直接变成后一级的输入，gulp-src返回当前文件流至可用插件；&quot; class=&quot;headerlink&quot; title=&quot;说明：src方法是指定需要处理的源文件的路径，gulp借鉴了Unix操作系统的管道（pipe）思想，前一级的输出，直接变成后一级的输入，gulp.src返回当前文件流至可用插件；&quot;&gt;&lt;/a&gt;说明：src方法是指定需要处理的源文件的路径，gulp借鉴了Unix操作系统的管道（pipe）思想，前一级的输出，直接变成后一级的输入，gulp.src返回当前文件流至可用插件；&lt;/h3&gt;&lt;h3 id=&quot;globs：-需要处理的源文件匹配符路径。类型-必填-：String-or-StringArray；&quot;&gt;&lt;a href=&quot;#globs：-需要处理的源文件匹配符路径。类型-必填-：String-or-StringArray；&quot; class=&quot;headerlink&quot; title=&quot;globs：  需要处理的源文件匹配符路径。类型(必填)：String or StringArray；&quot;&gt;&lt;/a&gt;globs：  需要处理的源文件匹配符路径。类型(必填)：String or StringArray；&lt;/h3&gt;&lt;p&gt;通配符路径匹配示例：&lt;/p&gt;
&lt;h4 id=&quot;“src-a-js”：指定具体文件；&quot;&gt;&lt;a href=&quot;#“src-a-js”：指定具体文件；&quot; class=&quot;headerlink&quot; title=&quot;“src/a.js”：指定具体文件；&quot;&gt;&lt;/a&gt;“src/a.js”：指定具体文件；&lt;/h4&gt;&lt;h4 id=&quot;“”：匹配所有文件-例：src-js-包含src下的所有js文件-；&quot;&gt;&lt;a href=&quot;#“”：匹配所有文件-例：src-js-包含src下的所有js文件-；&quot; class=&quot;headerlink&quot; title=&quot;“”：匹配所有文件    例：src/.js(包含src下的所有js文件)；&quot;&gt;&lt;/a&gt;“&lt;em&gt;”：匹配所有文件    例：src/&lt;/em&gt;.js(包含src下的所有js文件)；&lt;/h4&gt;&lt;h4 id=&quot;“”：匹配0个或多个子文件夹-例：src-js-包含src的0个或多个子文件夹下的js文件-；&quot;&gt;&lt;a href=&quot;#“”：匹配0个或多个子文件夹-例：src-js-包含src的0个或多个子文件夹下的js文件-；&quot; class=&quot;headerlink&quot; title=&quot;“”：匹配0个或多个子文件夹    例：src//*.js(包含src的0个或多个子文件夹下的js文件)；&quot;&gt;&lt;/a&gt;“&lt;strong&gt;”：匹配0个或多个子文件夹    例：src/&lt;/strong&gt;/*.js(包含src的0个或多个子文件夹下的js文件)；&lt;/h4&gt;&lt;h4 id=&quot;“-”：匹配多个属性-例：src-a-b-js-包含a-js和b-js文件-src-jpg-png-gif-src下的所有jpg-png-gif文件-；&quot;&gt;&lt;a href=&quot;#“-”：匹配多个属性-例：src-a-b-js-包含a-js和b-js文件-src-jpg-png-gif-src下的所有jpg-png-gif文件-；&quot; class=&quot;headerlink&quot; title=&quot;“{}”：匹配多个属性    例：src/{a,b}.js(包含a.js和b.js文件)  src/*.{jpg,png,gif}(src下的所有jpg/png/gif文件)；&quot;&gt;&lt;/a&gt;“{}”：匹配多个属性    例：src/{a,b}.js(包含a.js和b.js文件)  src/*.{jpg,png,gif}(src下的所有jpg/png/gif文件)；&lt;/h4&gt;&lt;h4 id=&quot;“-”：排除文件-例：-src-a-js-不包含src下的a-js文件-；&quot;&gt;&lt;a href=&quot;#“-”：排除文件-例：-src-a-js-不包含src下的a-js文件-；&quot; class=&quot;headerlink&quot; title=&quot;“!”：排除文件    例：!src/a.js(不包含src下的a.js文件)；&quot;&gt;&lt;/a&gt;“!”：排除文件    例：!src/a.js(不包含src下的a.js文件)；&lt;/h4&gt;
    
    </summary>
    
      <category term="gulp" scheme="http://sunhao.win/categories/gulp/"/>
    
    
      <category term="api" scheme="http://sunhao.win/tags/api/"/>
    
  </entry>
  
  <entry>
    <title>vue-lifecycle-vue生命周期</title>
    <link href="http://sunhao.win/articles/vue-lifecycle.html"/>
    <id>http://sunhao.win/articles/vue-lifecycle.html</id>
    <published>2017-06-23T06:28:58.000Z</published>
    <updated>2017-06-23T06:48:32.411Z</updated>
    
    <content type="html"><![CDATA[<p>这里的vue生命周期指的是一个组件创建到销毁的过程。</p>
<p>当组件激活  触发beforeCreate，Create，beforeMount，Mount<br>当组件不再显示销毁时，触发beforeDestroy，Destroy</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"app"</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">h3</span>&gt;</span>Let's check out the lifecycle of this hur' child.<span class="tag">&lt;/<span class="name">h3</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">h4</span>&gt;</span>Check the console!<span class="tag">&lt;/<span class="name">h4</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">button</span> @<span class="attr">click</span>=<span class="string">"toggleShow"</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">span</span> <span class="attr">v-if</span>=<span class="string">"isShowing"</span>&gt;</span>Hide child<span class="tag">&lt;/<span class="name">span</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">span</span> <span class="attr">v-else</span>&gt;</span>Show child<span class="tag">&lt;/<span class="name">span</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">button</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">hr</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">v-if</span>=<span class="string">"isShowing"</span>&gt;</span></div><div class="line">    <span class="tag">&lt;<span class="name">app-child</span>&gt;</span><span class="tag">&lt;/<span class="name">app-child</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line"></div><div class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">"text/x-template"</span> <span class="attr">id</span>=<span class="string">"childarea"</span>&gt;</span><span class="xml"></span></div><div class="line">  <span class="tag">&lt;<span class="name">div</span>&gt;</span></div><div class="line">  	<span class="tag">&lt;<span class="name">h4</span>&gt;</span>Here I am!<span class="tag">&lt;/<span class="name">h4</span>&gt;</span></div><div class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></div></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div></pre></td><td class="code"><pre><div class="line"><span class="selector-tag">body</span> &#123;</div><div class="line">  <span class="attribute">font-family</span>: <span class="string">'Bitter'</span>, serif;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-id">#app</span> &#123;</div><div class="line">  <span class="attribute">text-align</span>: center;</div><div class="line">  <span class="attribute">margin</span>: <span class="number">60px</span>;</div><div class="line">  <span class="attribute">max-width</span>: <span class="number">320px</span>;</div><div class="line">  <span class="attribute">margin</span>: <span class="number">0</span> auto;</div><div class="line">  <span class="attribute">display</span>: table;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-class">.num</span> &#123;</div><div class="line">  <span class="attribute">color</span>: <span class="number">#AF007E</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-tag">button</span> &#123;</div><div class="line">  <span class="attribute">font-family</span>: <span class="string">'Bitter'</span>;</div><div class="line">  <span class="attribute">background</span>: <span class="number">#c62735</span>;</div><div class="line">  <span class="attribute">color</span>: white;</div><div class="line">  <span class="attribute">border</span>: <span class="number">0</span>;</div><div class="line">  <span class="attribute">padding</span>: <span class="number">5px</span> <span class="number">15px</span>;</div><div class="line">  <span class="attribute">margin</span>: <span class="number">0</span> <span class="number">10px</span>;</div><div class="line">  <span class="attribute">border-radius</span>: <span class="number">4px</span>;</div><div class="line">  <span class="attribute">outline</span>: <span class="number">0</span>;</div><div class="line">  <span class="attribute">cursor</span>: pointer;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-tag">h4</span> &#123;</div><div class="line">  <span class="attribute">margin</span>: <span class="number">0</span> <span class="number">0</span> <span class="number">15px</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-tag">hr</span> &#123;</div><div class="line">  <span class="attribute">border-color</span>: <span class="number">#F2FAFF</span>;</div><div class="line">  <span class="attribute">opacity</span>: <span class="number">0.5</span>;</div><div class="line">  <span class="attribute">margin</span>: <span class="number">15px</span> <span class="number">0</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">const</span> Child = &#123;</div><div class="line">  <span class="attr">template</span>: <span class="string">'#childarea'</span>,</div><div class="line">  beforeCreate() &#123;</div><div class="line">    <span class="built_in">console</span>.log(<span class="string">"beforeCreate!"</span>);</div><div class="line">  &#125;, </div><div class="line">  created() &#123;</div><div class="line">    <span class="built_in">console</span>.log(<span class="string">"created!"</span>);</div><div class="line">  &#125;, </div><div class="line">  beforeMount() &#123;</div><div class="line">    <span class="built_in">console</span>.log(<span class="string">"beforeMount!"</span>);</div><div class="line">  &#125;, </div><div class="line">  mounted() &#123;</div><div class="line">    <span class="built_in">console</span>.log(<span class="string">"mounted!"</span>);</div><div class="line">  &#125;, </div><div class="line">  beforeDestroy() &#123;</div><div class="line">    <span class="built_in">console</span>.log(<span class="string">"beforeDestroy!"</span>);</div><div class="line">  &#125;, </div><div class="line">  destroyed() &#123;</div><div class="line">    <span class="built_in">console</span>.log(<span class="string">"destroyed!"</span>);</div><div class="line">  &#125;</div><div class="line">&#125;;</div><div class="line"></div><div class="line"><span class="keyword">new</span> Vue(&#123;</div><div class="line">  <span class="attr">el</span>: <span class="string">'#app'</span>,</div><div class="line">  data() &#123;</div><div class="line">    <span class="keyword">return</span> &#123;</div><div class="line">      <span class="attr">isShowing</span>: <span class="literal">false</span> </div><div class="line">    &#125;</div><div class="line">  &#125;,</div><div class="line">  <span class="attr">methods</span>: &#123;</div><div class="line">    toggleShow() &#123;</div><div class="line">      <span class="keyword">this</span>.isShowing = !<span class="keyword">this</span>.isShowing;</div><div class="line">    &#125;</div><div class="line">  &#125;,</div><div class="line">  <span class="attr">components</span>: &#123;</div><div class="line">    <span class="attr">appChild</span>: Child</div><div class="line">  &#125;</div><div class="line">&#125;);</div></pre></td></tr></table></figure>
<a id="more"></a>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;这里的vue生命周期指的是一个组件创建到销毁的过程。&lt;/p&gt;
&lt;p&gt;当组件激活  触发beforeCreate，Create，beforeMount，Mount&lt;br&gt;当组件不再显示销毁时，触发beforeDestroy，Destroy&lt;/p&gt;
&lt;figure class=&quot;highlight html&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;18&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;app&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;h3&lt;/span&gt;&amp;gt;&lt;/span&gt;Let&#39;s check out the lifecycle of this hur&#39; child.&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;h3&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;h4&lt;/span&gt;&amp;gt;&lt;/span&gt;Check the console!&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;h4&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;button&lt;/span&gt; @&lt;span class=&quot;attr&quot;&gt;click&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;toggleShow&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;v-if&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;isShowing&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;Hide child&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;v-else&lt;/span&gt;&amp;gt;&lt;/span&gt;Show child&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;span&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;button&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;hr&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;v-if&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;isShowing&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;app-child&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;app-child&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;text/x-template&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;string&quot;&gt;&quot;childarea&quot;&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;xml&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  	&lt;span class=&quot;tag&quot;&gt;&amp;lt;&lt;span class=&quot;name&quot;&gt;h4&lt;/span&gt;&amp;gt;&lt;/span&gt;Here I am!&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;h4&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;div&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;tag&quot;&gt;&amp;lt;/&lt;span class=&quot;name&quot;&gt;script&lt;/span&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;figure class=&quot;highlight css&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;18&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;19&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;20&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;21&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;22&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;23&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;24&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;25&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;26&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;27&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;28&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;29&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;30&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;31&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;32&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;33&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;34&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;35&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;36&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;37&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;body&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;font-family&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&#39;Bitter&#39;&lt;/span&gt;, serif;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-id&quot;&gt;#app&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;text-align&lt;/span&gt;: center;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;60px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;max-width&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;320px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt; auto;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;display&lt;/span&gt;: table;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-class&quot;&gt;.num&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#AF007E&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;button&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;font-family&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&#39;Bitter&#39;&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;background&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#c62735&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;color&lt;/span&gt;: white;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;border&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;padding&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;5px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;15px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;10px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;border-radius&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;4px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;outline&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;cursor&lt;/span&gt;: pointer;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;h4&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;15px&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;selector-tag&quot;&gt;hr&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;border-color&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;#F2FAFF&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;opacity&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;0.5&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attribute&quot;&gt;margin&lt;/span&gt;: &lt;span class=&quot;number&quot;&gt;15px&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;figure class=&quot;highlight javascript&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;16&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;17&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;18&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;19&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;20&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;21&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;22&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;23&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;24&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;25&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;26&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;27&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;28&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;29&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;30&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;31&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;32&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;33&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;34&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;35&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;36&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;37&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;38&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;const&lt;/span&gt; Child = &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attr&quot;&gt;template&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&#39;#childarea&#39;&lt;/span&gt;,&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  beforeCreate() &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.log(&lt;span class=&quot;string&quot;&gt;&quot;beforeCreate!&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  created() &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.log(&lt;span class=&quot;string&quot;&gt;&quot;created!&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  beforeMount() &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.log(&lt;span class=&quot;string&quot;&gt;&quot;beforeMount!&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  mounted() &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.log(&lt;span class=&quot;string&quot;&gt;&quot;mounted!&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  beforeDestroy() &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.log(&lt;span class=&quot;string&quot;&gt;&quot;beforeDestroy!&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;, &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  destroyed() &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;built_in&quot;&gt;console&lt;/span&gt;.log(&lt;span class=&quot;string&quot;&gt;&quot;destroyed!&quot;&lt;/span&gt;);&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;new&lt;/span&gt; Vue(&amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attr&quot;&gt;el&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&#39;#app&#39;&lt;/span&gt;,&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  data() &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;      &lt;span class=&quot;attr&quot;&gt;isShowing&lt;/span&gt;: &lt;span class=&quot;literal&quot;&gt;false&lt;/span&gt; &lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;,&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attr&quot;&gt;methods&lt;/span&gt;: &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    toggleShow() &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;      &lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.isShowing = !&lt;span class=&quot;keyword&quot;&gt;this&lt;/span&gt;.isShowing;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;,&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &lt;span class=&quot;attr&quot;&gt;components&lt;/span&gt;: &amp;#123;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;    &lt;span class=&quot;attr&quot;&gt;appChild&lt;/span&gt;: Child&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;  &amp;#125;&lt;/div&gt;&lt;div class=&quot;line&quot;&gt;&amp;#125;);&lt;/div&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
    
    </summary>
    
      <category term="vue" scheme="http://sunhao.win/categories/vue/"/>
    
    
      <category term="生命周期" scheme="http://sunhao.win/tags/%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F/"/>
    
  </entry>
  
  <entry>
    <title>webpack-config</title>
    <link href="http://sunhao.win/articles/webpack-config.html"/>
    <id>http://sunhao.win/articles/webpack-config.html</id>
    <published>2017-06-21T08:24:49.000Z</published>
    <updated>2017-06-21T08:28:34.564Z</updated>
    
    <content type="html"><![CDATA[<p>“build-env”: “rimraf dist &amp;&amp; set NODE_ENV=production&amp;&amp; webpack”,</p>
<p>切记 set NODE_ENV=production<br>其中=号不要隔开,不然会出错。因为这个是设置DOS下的环境<br><a id="more"></a></p>
]]></content>
    
    <summary type="html">
    
      &lt;p&gt;“build-env”: “rimraf dist &amp;amp;&amp;amp; set NODE_ENV=production&amp;amp;&amp;amp; webpack”,&lt;/p&gt;
&lt;p&gt;切记 set NODE_ENV=production&lt;br&gt;其中=号不要隔开,不然会出错。因为这个是设置DOS下的环境&lt;br&gt;
    
    </summary>
    
      <category term="webpack" scheme="http://sunhao.win/categories/webpack/"/>
    
    
      <category term="webpack" scheme="http://sunhao.win/tags/webpack/"/>
    
      <category term="config" scheme="http://sunhao.win/tags/config/"/>
    
  </entry>
  
  <entry>
    <title>ssh详细登录过程</title>
    <link href="http://sunhao.win/articles/linux-ssh.html"/>
    <id>http://sunhao.win/articles/linux-ssh.html</id>
    <published>2017-06-20T07:22:00.000Z</published>
    <updated>2017-06-20T07:25:57.653Z</updated>
    
    <content type="html"><![CDATA[<h3 id="首先说下相关概念"><a href="#首先说下相关概念" class="headerlink" title="首先说下相关概念:"></a>首先说下相关概念:</h3><p>明文：需要秘密传送的消息。</p>
<p>密文：明文经过密码变换后的消息。</p>
<p>加密：由明文到密文的变换。</p>
<p>解密：从密文恢复出明文的过程。</p>
<p>破解：非法接收者试图从密文分析出明文的过程。</p>
<p>加密算法：对明文进行加密时采用的一组规则。</p>
<p>解密算法：对密文进行解密时采用的一组规则。</p>
<p>密钥：加密和解密时使用的一组密码信息。</p>
<p>对称加密：是采用单钥密码系统的加密方法，使用同一密钥对信息进行加密和解密的加密方法。</p>
<p>非对称加密：需要两个密钥：公共密钥和私有密钥，它们成对出现，公钥加密的数据有且只有私钥能解密，私钥加密的数据有且只有公钥解密，相对于“对称加密”，“非对称加密”加密方法加密和解密使用不同的密钥，所以叫“非对称加密”加密方法。</p>
<p>对称加密和非对称加密的区别：在于加密和解密是否使用的同一个密钥。<br> <a id="more"></a></p>
<h3 id="加密、身份认证、数字签名认证："><a href="#加密、身份认证、数字签名认证：" class="headerlink" title="加密、身份认证、数字签名认证："></a>加密、身份认证、数字签名认证：</h3><pre><code> 加密：将数据资料加密，使得非法用户即便获取加密后的资料，也无法获取正确的资料内容，所以数据加密可以保证数据防止监听攻击；其重点在于数据的安全性。

身份认证：判断某身份的真实性，确认身份后，系统才可以依不同的身份赋予不同的权限；其重点在于用户的真实性。

数字签名认证：首先&quot;数字签名&quot;就是附加在数据单元上的一些数据，或是对数据单元所作的密码变换。这种数据或变换允许接收者判断数据的来源和数据的完整性，防止被伪造篡改。数字签名认证侧重于把保证数据的完整性，防止被伪造和篡改。
</code></pre><p><img src="http://ojlt0g866.bkt.clouddn.com/blog/20170620/152108540.png" alt="mark"></p>
<h3 id="认证原理-有2种认证方式："><a href="#认证原理-有2种认证方式：" class="headerlink" title="认证原理: 有2种认证方式："></a>认证原理: 有2种认证方式：</h3><p>基于账号和口令的验证方式 和 基于公钥和私钥的验证方式</p>
<p>ssh的登录过程分为5个阶段<br>        1、版本号协商阶段<br>        2、密钥和算法协商阶段<br>        3、认证阶段<br>        4、会话请求阶段<br>        5、会话交互阶段</p>
<h4 id="1、版本号协商阶段"><a href="#1、版本号协商阶段" class="headerlink" title="1、版本号协商阶段"></a>1、版本号协商阶段</h4><pre><code>服务端打开端口22，等待客户连接。
客户端向服务端发起TCP连接，连接建立后，服务端向客户端发送第一个报文，包括版本标志字符串，格式为“协议版本号 次协议版本号 软件版本号”。
客户端收到报文后，解析协议版本号，如果服务端的协议版本号比自己的低，且客户端能支持服务端的低版本，就使用服务端的协议号，否则使用自己的协议版本号。
客户端回复服务端一个报文，包含了客户端决定使用的协议版本号。
服务端比较客户端发过来的版本号，决定是否能同客户端交互。
如果协商成功，就进入密钥和算法协商阶段。否则服务端断开TCP连接。
</code></pre><h4 id="2、密钥和算法协商阶段"><a href="#2、密钥和算法协商阶段" class="headerlink" title="2、密钥和算法协商阶段"></a>2、密钥和算法协商阶段</h4><pre><code>服务端和客户端分别发送算法协商报文给对方，报文中包含自己支持的公钥算法列表、加密算法列表、消息验证码算法列表、压缩算法列表等。
服务端和客户端根据对方和自己支持的算法得出最终使用的算法。
服务端和客户端利用DH交换算法、主机密钥对等参数，生成会话密钥和会话ID。
    c公 客户端公钥
    c密 客户端密钥
    s公 服务端公钥
    s密 服务端密钥
在版本号协商阶段完成后：
服务端将 s公 发送给客户端。
服务端生成会话ID ，设为 id ，发送给客户端。
客户端生成会话密钥，设为 key ，并计算 res = id 异或 key。
客户端将 res 用 s公 进行加密，将结果发送给服务端。
服务端用 s密 进行解密，得到 res。
服务器计算 res 异或 id，得到 key。
至此服务端和客户端都知道了会话密钥和会话ID，以后的数据传输都使用会话密钥进行加密和解密。
</code></pre><h4 id="3、认证阶段"><a href="#3、认证阶段" class="headerlink" title="3、认证阶段"></a>3、认证阶段</h4><pre><code>基于账号和口令的验证方式：
    客户端使用密钥和算法协商阶段生成的会话密钥加密账号、认证方法、口令，将结果发送给服务器。
    服务端使用获得的会话密钥解密报文，得到账号和口令。
    服务端对这个账号和口令进行判断，如果失败，向客户端发送认证失败报文，其中包含了可以再次认证的方法列表。
    客户端从认证方法列表中选择一种方法进行再次认证。
    这个过程反复进行，直到认证成功或者认证次数达到上限，服务端关闭本次TCP连接。
基于公钥和私钥的验证方式：
    使用ssh-keygen程序生成公钥 id_dsa.pub 和私钥 id_dsa，一般是在客户端上生成，然后把 id_dsa.pub 通过某种方式发送给服务端。
    服务端放在将要远程登录过来的那个账号的目录的.ssh目录下面。
    客户端使用密钥和算法协商阶段生成的会话密钥加密账号、认证方法、id_dsa.pub，将结果发送给服务端。
    服务端使用会话密钥解密报文，得到账号、id_dsa.pub。    服务端在这个账号的目录的.ssh目录下找对应的公钥，如果没有找到，发送失败消息给客户端，如果找到，比较客户发送过来的这个公钥和找到的公钥，如果内容相同，服务端生成一个随机的字符串，简称“质询”，然后使用找到的公钥加密这个质询，然后使用会话密钥再次加密。
    服务端把这个双重加密的数据发送给客户端。
    客户端使用会话密钥解密报文，然后使用id_dsa再次解密数据，得到质询。
    客户端使用会话密钥加密质询，发送给服务端。
    服务端使用会话密钥解密报文，得到质询，判断是不是自己生成的那个质询，如果不相同，发送失败消息给客户端，如果相同，认证通过。
</code></pre>]]></content>
    
    <summary type="html">
    
      &lt;h3 id=&quot;首先说下相关概念&quot;&gt;&lt;a href=&quot;#首先说下相关概念&quot; class=&quot;headerlink&quot; title=&quot;首先说下相关概念:&quot;&gt;&lt;/a&gt;首先说下相关概念:&lt;/h3&gt;&lt;p&gt;明文：需要秘密传送的消息。&lt;/p&gt;
&lt;p&gt;密文：明文经过密码变换后的消息。&lt;/p&gt;
&lt;p&gt;加密：由明文到密文的变换。&lt;/p&gt;
&lt;p&gt;解密：从密文恢复出明文的过程。&lt;/p&gt;
&lt;p&gt;破解：非法接收者试图从密文分析出明文的过程。&lt;/p&gt;
&lt;p&gt;加密算法：对明文进行加密时采用的一组规则。&lt;/p&gt;
&lt;p&gt;解密算法：对密文进行解密时采用的一组规则。&lt;/p&gt;
&lt;p&gt;密钥：加密和解密时使用的一组密码信息。&lt;/p&gt;
&lt;p&gt;对称加密：是采用单钥密码系统的加密方法，使用同一密钥对信息进行加密和解密的加密方法。&lt;/p&gt;
&lt;p&gt;非对称加密：需要两个密钥：公共密钥和私有密钥，它们成对出现，公钥加密的数据有且只有私钥能解密，私钥加密的数据有且只有公钥解密，相对于“对称加密”，“非对称加密”加密方法加密和解密使用不同的密钥，所以叫“非对称加密”加密方法。&lt;/p&gt;
&lt;p&gt;对称加密和非对称加密的区别：在于加密和解密是否使用的同一个密钥。&lt;br&gt;
    
    </summary>
    
      <category term="linux" scheme="http://sunhao.win/categories/linux/"/>
    
    
      <category term="ssh" scheme="http://sunhao.win/tags/ssh/"/>
    
  </entry>
  
  <entry>
    <title>npm版本说明及安装范围版本</title>
    <link href="http://sunhao.win/articles/npm-install.html"/>
    <id>http://sunhao.win/articles/npm-install.html</id>
    <published>2017-06-15T06:38:39.000Z</published>
    <updated>2017-06-15T07:50:02.611Z</updated>
    
    <content type="html"><![CDATA[<p>最近安装测试环境需要安装webpack1版本。但是用cnpm安装的时候默认已经是2.6.1了</p>
<p>那么我们怎么安装指定版本呢。</p>
<h3 id="Semver语义化版本控制规范"><a href="#Semver语义化版本控制规范" class="headerlink" title="Semver语义化版本控制规范"></a>Semver语义化版本控制规范</h3><p>首先node采用semver规范，感兴趣的可以研究下。在这我们要明白版本号。<br><a href="http://semver.org/lang/zh-CN/" target="_blank" rel="external">http://semver.org/lang/zh-CN/</a></p>
<p>版本格式：主版本号.次版本号.修订号，版本号递增规则如下：<br>主版本号：当你做了不兼容的API 修改，<br>次版本号：当你做了向下兼容的功能性新增，<br>修订号：当你做了向下兼容的问题修正。<br>先行版本号及版本编译信息可以加到“主版本号.次版本号.修订号”的后面，作为延伸<br>例如1.2.19   1是版本号 ，2是次版本号，19是修订号 </p>
<a id="more"></a>
<h3 id="我们看看我们配置的依赖包"><a href="#我们看看我们配置的依赖包" class="headerlink" title="我们看看我们配置的依赖包"></a>我们看看我们配置的依赖包</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">&quot;devDependencies&quot;: &#123;</div><div class="line">   &quot;rimraf&quot;: &quot;^2.6.1&quot;,</div><div class="line">   &quot;webpack&quot;: &quot;^2.6.1&quot;</div><div class="line"> &#125;</div></pre></td></tr></table></figure>
<p>其中^2.6.1就是版本号。我们看看官方解释</p>
<p>dependencies</p>
<p>Dependencies are specified in a simple object that maps a package name to a version range. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or git URL.</p>
<p>Dependencies是将包名映射到版本范围的简单对象。版本范围是一个字符串，它具有一个或多个空格分隔的描述符。Dependencies也可以用tarball或git来标识。</p>
<p>Please do not put test harnesses or transpilers in your dependencies object. See devDependencies, below.</p>
<p>See semver for more details about specifying version ranges.</p>
<p>请不要在您的依赖对象中放置testharnesses或transpilers。请看下面的devDependencies。</p>
<p>ps:testharnesses测试实例工具，transpilers编译es6的工具</p>
<pre><code>version Must match version exactly
版本必须精确匹配

&gt;version Must be greater than version
&gt;大于指定版本

&gt;=version etc
&gt;=大于等于指定版本

&lt;version
&lt;=小于指定版本

&lt;=version
&lt;=小于等于指定版本

~version &quot;Approximately equivalent to version&quot; See semver
~近似于版本  例如2.1.1版本  他的近似版本类似 2.1.x  x任意


^version &quot;Compatible with version&quot; See semver
^兼容版本

1.2.x 1.2.0, 1.2.1, etc., but not 1.3.0
例如1.2.x 1.2.0, 1.2.1, 等., 但1.3.0就不是了

http://... See &apos;URLs as Dependencies&apos; below

* Matches any version
*匹配任意版本

&quot;&quot; (just an empty string) Same as *
&quot;&quot;(空字符串)和*一样

version1 - version2 Same as &gt;=version1 &lt;=version2.
version1 - version2 例如 &gt;=version1 &lt;=version2. 大于等于version1小于等于version2

range1 || range2 Passes if either range1 or range2 are satisfied.
range1 || range2 例如1.2.1||2.2.1 这两个版本都可以。
</code></pre><p>git… See ‘Git URLs as Dependencies’ below</p>
<p>git方式<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">git://github.com/user/project.git#commit-ish</div><div class="line">git+ssh://user@hostname:project.git#commit-ish</div><div class="line">git+ssh://user@hostname/project.git#commit-ish</div><div class="line">git+http://user@hostname/project/blah.git#commit-ish</div><div class="line">git+https://user@hostname/project/blah.git#commit-ish</div></pre></td></tr></table></figure></p>
<p>user/repo See ‘GitHub URLs’ below</p>
<p>github方式<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">  &quot;name&quot;: &quot;foo&quot;,</div><div class="line">  &quot;version&quot;: &quot;0.0.0&quot;,</div><div class="line">  &quot;dependencies&quot;: &#123;</div><div class="line">    &quot;express&quot;: &quot;expressjs/express&quot;,</div><div class="line">    &quot;mocha&quot;: &quot;mochajs/mocha#4727d357ea&quot;,</div><div class="line">    &quot;module&quot;: &quot;user/repo#feature\/branch&quot;</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>tag A specific version tagged and published as tag See npm-dist-tag</p>
<p>通过一个版本标记类似，tag是我们发布包做的标记。<br>    npm install name@tag </p>
<pre><code>path/path/path See Local Paths below
</code></pre><p>通过本地安装<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&#123;</div><div class="line">  &quot;name&quot;: &quot;baz&quot;,</div><div class="line">  &quot;dependencies&quot;: &#123;</div><div class="line">    &quot;bar&quot;: &quot;file:../foo/bar&quot;</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>For example, these are all valid:</p>
<p>示例</p>
<pre><code>{ &quot;dependencies&quot; :
  { &quot;foo&quot; : &quot;1.0.0 - 2.9999.9999&quot;
  , &quot;bar&quot; : &quot;&gt;=1.0.2 &lt;2.1.2&quot;
  , &quot;baz&quot; : &quot;&gt;1.0.2 &lt;=2.3.4&quot;
  , &quot;boo&quot; : &quot;2.0.1&quot;
  , &quot;qux&quot; : &quot;&lt;1.0.0 || &gt;=2.3.1 &lt;2.4.5 || &gt;=2.5.2 &lt;3.0.0&quot;
  , &quot;asd&quot; : &quot;http://asdf.com/asdf.tar.gz&quot;
  , &quot;til&quot; : &quot;~1.2&quot;
  , &quot;elf&quot; : &quot;~1.2.3&quot;
  , &quot;two&quot; : &quot;2.x&quot;
  , &quot;thr&quot; : &quot;3.3.x&quot;
  , &quot;lat&quot; : &quot;latest&quot;
  , &quot;dyl&quot; : &quot;file:../dyl&quot;
  }
}
</code></pre><h3 id="我们再看一下安装规范"><a href="#我们再看一下安装规范" class="headerlink" title="我们再看一下安装规范"></a>我们再看一下安装规范</h3><pre><code>npm install &lt;name&gt;@&lt;version&gt;

指定安装的package 版本

npm install (with no args in a package dir)
npm install &lt;tarball file&gt;
npm install &lt;tarball url&gt;
npm install &lt;folder&gt;
npm install [@&lt;scope&gt;/]&lt;name&gt; [--save|--save-dev|--save-optional] [--save-exact]
npm install [@&lt;scope&gt;/]&lt;name&gt;@&lt;tag&gt;
npm install [@&lt;scope&gt;/]&lt;name&gt;@&lt;version&gt;
npm install [@&lt;scope&gt;/]&lt;name&gt;@&lt;version range&gt;
npm i (with any of the previous argument usage)
</code></pre><p>好了   说重点  安装我们的webpack1</p>
<pre><code>npm install webpack@^1.* --save-dev
</code></pre><h3 id="额外赠送"><a href="#额外赠送" class="headerlink" title="额外赠送"></a>额外赠送</h3><p>npm init  会引导你创建一个package.json文件，包括名称、版本、作者这些信息等</p>
<p>npm remove <name>移除</name></p>
<p>npm update <name>更新</name></p>
<p>npm ls 列出当前安装的了所有包</p>
<p>npm root 查看当前包的安装路径</p>
<p>npm root -g  查看全局的包的安装路径</p>
]]></content>
    
    <summary type="html">
    
      &lt;p&gt;最近安装测试环境需要安装webpack1版本。但是用cnpm安装的时候默认已经是2.6.1了&lt;/p&gt;
&lt;p&gt;那么我们怎么安装指定版本呢。&lt;/p&gt;
&lt;h3 id=&quot;Semver语义化版本控制规范&quot;&gt;&lt;a href=&quot;#Semver语义化版本控制规范&quot; class=&quot;headerlink&quot; title=&quot;Semver语义化版本控制规范&quot;&gt;&lt;/a&gt;Semver语义化版本控制规范&lt;/h3&gt;&lt;p&gt;首先node采用semver规范，感兴趣的可以研究下。在这我们要明白版本号。&lt;br&gt;&lt;a href=&quot;http://semver.org/lang/zh-CN/&quot; target=&quot;_blank&quot; rel=&quot;external&quot;&gt;http://semver.org/lang/zh-CN/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;版本格式：主版本号.次版本号.修订号，版本号递增规则如下：&lt;br&gt;主版本号：当你做了不兼容的API 修改，&lt;br&gt;次版本号：当你做了向下兼容的功能性新增，&lt;br&gt;修订号：当你做了向下兼容的问题修正。&lt;br&gt;先行版本号及版本编译信息可以加到“主版本号.次版本号.修订号”的后面，作为延伸&lt;br&gt;例如1.2.19   1是版本号 ，2是次版本号，19是修订号 &lt;/p&gt;
    
    </summary>
    
      <category term="npm" scheme="http://sunhao.win/categories/npm/"/>
    
    
      <category term="npm" scheme="http://sunhao.win/tags/npm/"/>
    
      <category term="install" scheme="http://sunhao.win/tags/install/"/>
    
      <category term="npm版本" scheme="http://sunhao.win/tags/npm%E7%89%88%E6%9C%AC/"/>
    
  </entry>
  
</feed>
