<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Javascript on Bigshans&#39; Blog</title>
    <link>https://bigshans.github.io/tags/javascript/</link>
    <description>Recent content in Javascript on Bigshans&#39; Blog</description>
    <generator>Hugo</generator>
    <language>en</language>
    <copyright>bigshans</copyright>
    <lastBuildDate>Sat, 14 Oct 2023 11:52:10 +0800</lastBuildDate>
    <atom:link href="https://bigshans.github.io/tags/javascript/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>函数柯里化</title>
      <link>https://bigshans.github.io/post/curry/</link>
      <pubDate>Sat, 14 Oct 2023 11:52:10 +0800</pubDate>
      <guid>https://bigshans.github.io/post/curry/</guid>
      <description>&lt;p&gt;函数柯里化是一种可以将函数转换为另一个函数的技巧，通常是用来减少函数参数的。&lt;/p&gt;&#xA;&lt;p&gt;用一个简单的例子以表示这种使用:&lt;/p&gt;&#xA;&lt;div class=&#34;sourceCode&#34; id=&#34;cb1&#34;&gt;&lt;pre class=&#34;sourceCode javascript&#34;&gt;&lt;code class=&#34;sourceCode javascript&#34;&gt;&lt;span id=&#34;cb1-1&#34;&gt;&lt;a href=&#34;#cb1-1&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&lt;span class=&#34;kw&#34;&gt;function&lt;/span&gt; &lt;span class=&#34;fu&#34;&gt;sum&lt;/span&gt;(a&lt;span class=&#34;op&#34;&gt;,&lt;/span&gt; b) {&lt;/span&gt;&#xA;&lt;span id=&#34;cb1-2&#34;&gt;&lt;a href=&#34;#cb1-2&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;  &lt;span class=&#34;cf&#34;&gt;return&lt;/span&gt; a &lt;span class=&#34;op&#34;&gt;+&lt;/span&gt; b&lt;span class=&#34;op&#34;&gt;;&lt;/span&gt;&lt;/span&gt;&#xA;&lt;span id=&#34;cb1-3&#34;&gt;&lt;a href=&#34;#cb1-3&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;}&lt;/span&gt;&#xA;&lt;span id=&#34;cb1-4&#34;&gt;&lt;a href=&#34;#cb1-4&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&lt;/span&gt;&#xA;&lt;span id=&#34;cb1-5&#34;&gt;&lt;a href=&#34;#cb1-5&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&lt;span class=&#34;kw&#34;&gt;const&lt;/span&gt; add1 &lt;span class=&#34;op&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;fu&#34;&gt;curry&lt;/span&gt;((b) &lt;span class=&#34;kw&#34;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&#34;fu&#34;&gt;sum&lt;/span&gt;(&lt;span class=&#34;dv&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;op&#34;&gt;,&lt;/span&gt; b))&lt;span class=&#34;op&#34;&gt;;&lt;/span&gt;&lt;/span&gt;&#xA;&lt;span id=&#34;cb1-6&#34;&gt;&lt;a href=&#34;#cb1-6&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&lt;span class=&#34;bu&#34;&gt;console&lt;/span&gt;&lt;span class=&#34;op&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;fu&#34;&gt;log&lt;/span&gt;(&lt;span class=&#34;fu&#34;&gt;add1&lt;/span&gt;(&lt;span class=&#34;dv&#34;&gt;10&lt;/span&gt;))&lt;span class=&#34;op&#34;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;这里我们实际上固定了 &lt;code&gt;sum&lt;/code&gt; 的参数，但这里我只被允许加上 1&#xA;，我们可以更灵活一些。&lt;/p&gt;</description>
    </item>
    <item>
      <title>JavaScript 的标签模板字符串</title>
      <link>https://bigshans.github.io/post/tagged-template-string/</link>
      <pubDate>Fri, 16 Dec 2022 10:49:05 +0800</pubDate>
      <guid>https://bigshans.github.io/post/tagged-template-string/</guid>
      <description>&lt;p&gt;标签模板是个看起来很 Magic 的语法，写起来像是这样。&lt;/p&gt;&#xA;&lt;div class=&#34;sourceCode&#34; id=&#34;cb1&#34;&gt;&lt;pre class=&#34;sourceCode javascript&#34;&gt;&lt;code class=&#34;sourceCode javascript&#34;&gt;&lt;span id=&#34;cb1-1&#34;&gt;&lt;a href=&#34;#cb1-1&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&lt;span class=&#34;bu&#34;&gt;console&lt;/span&gt;&lt;span class=&#34;op&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;fu&#34;&gt;log&lt;/span&gt;&lt;span class=&#34;vs&#34;&gt;`Hello, World!`&lt;/span&gt;&lt;span class=&#34;op&#34;&gt;;&lt;/span&gt;&lt;/span&gt;&#xA;&lt;span id=&#34;cb1-2&#34;&gt;&lt;a href=&#34;#cb1-2&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&lt;span class=&#34;co&#34;&gt;// Output: [&amp;#34;Hello, World!&amp;#34;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;实际上，这里的模板标签被转换成这样的一句调用。&lt;/p&gt;&#xA;&lt;div class=&#34;sourceCode&#34; id=&#34;cb2&#34;&gt;&lt;pre class=&#34;sourceCode javascript&#34;&gt;&lt;code class=&#34;sourceCode javascript&#34;&gt;&lt;span id=&#34;cb2-1&#34;&gt;&lt;a href=&#34;#cb2-1&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&lt;span class=&#34;bu&#34;&gt;console&lt;/span&gt;&lt;span class=&#34;op&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;fu&#34;&gt;log&lt;/span&gt;&lt;span class=&#34;op&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;fu&#34;&gt;call&lt;/span&gt;(&lt;span class=&#34;bu&#34;&gt;console&lt;/span&gt;&lt;span class=&#34;op&#34;&gt;,&lt;/span&gt; [&lt;span class=&#34;st&#34;&gt;&amp;#39;Hello, World!&amp;#39;&lt;/span&gt;])&lt;span class=&#34;op&#34;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;如果我们有用变量的话，&lt;/p&gt;&#xA;&lt;div class=&#34;sourceCode&#34; id=&#34;cb3&#34;&gt;&lt;pre class=&#34;sourceCode javascript&#34;&gt;&lt;code class=&#34;sourceCode javascript&#34;&gt;&lt;span id=&#34;cb3-1&#34;&gt;&lt;a href=&#34;#cb3-1&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&lt;span class=&#34;kw&#34;&gt;const&lt;/span&gt; name &lt;span class=&#34;op&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;st&#34;&gt;&amp;#39;world&amp;#39;&lt;/span&gt;&lt;span class=&#34;op&#34;&gt;;&lt;/span&gt;&lt;/span&gt;&#xA;&lt;span id=&#34;cb3-2&#34;&gt;&lt;a href=&#34;#cb3-2&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&lt;span class=&#34;bu&#34;&gt;console&lt;/span&gt;&lt;span class=&#34;op&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;fu&#34;&gt;log&lt;/span&gt;&lt;span class=&#34;vs&#34;&gt;`Hello, &lt;/span&gt;&lt;span class=&#34;sc&#34;&gt;${&lt;/span&gt;name&lt;span class=&#34;sc&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;vs&#34;&gt;!`&lt;/span&gt;&lt;/span&gt;&#xA;&lt;span id=&#34;cb3-3&#34;&gt;&lt;a href=&#34;#cb3-3&#34; aria-hidden=&#34;true&#34; tabindex=&#34;-1&#34;&gt;&lt;/a&gt;&lt;span class=&#34;co&#34;&gt;// Output: [ &amp;#39;Hello, &amp;#39;, &amp;#39;!&amp;#39; ] world&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;就会被转换成这样一句调用。&lt;/p&gt;</description>
    </item>
    <item>
      <title>《事件捕获与事件冒泡》补遗</title>
      <link>https://bigshans.github.io/post/%E4%BA%8B%E4%BB%B6%E6%8D%95%E8%8E%B7%E4%B8%8E%E4%BA%8B%E4%BB%B6%E5%86%92%E6%B3%A1/</link>
      <pubDate>Tue, 17 May 2022 10:46:28 +0800</pubDate>
      <guid>https://bigshans.github.io/post/%E4%BA%8B%E4%BB%B6%E6%8D%95%E8%8E%B7%E4%B8%8E%E4%BA%8B%E4%BB%B6%E5%86%92%E6%B3%A1/</guid>
      <description>&lt;p&gt;阅读的文章是&lt;a href=&#34;https://juejin.cn/post/6931631885135118350&#34;&gt;关于事件捕获与事件冒泡先后执行顺序 &lt;/a&gt; ，写得挺好的，就是我读的时候漏了一点。&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code class=&#34;language-html&#34;&gt;&amp;lt;!DOCTYPE html&amp;gt;&#xA;&amp;lt;html&amp;gt;&#xA;  &amp;lt;head&amp;gt;&#xA;    &amp;lt;meta charset=&amp;quot;utf-8&amp;quot;&amp;gt;&#xA;    &amp;lt;meta name=&amp;quot;viewport&amp;quot; content=&amp;quot;width=device-width&amp;quot;&amp;gt;&#xA;    &amp;lt;title&amp;gt;DOM 冒泡&amp;lt;/title&amp;gt;&#xA;    &amp;lt;style type=&amp;quot;text/css&amp;quot; media=&amp;quot;all&amp;quot;&amp;gt;&#xA;#parent {&#xA;  height: 100px;&#xA;  width: 100%;&#xA;  background: green;&#xA;}&#xA;        #child {&#xA;          height: 50px;&#xA;          width: 50%;&#xA;          background: yellow;&#xA;        }&#xA;        #button {&#xA;          height: 30px;&#xA;          width: 10%;&#xA;          background: white;&#xA;        }&#xA;    &amp;lt;/style&amp;gt;&#xA;  &amp;lt;/head&amp;gt;&#xA;  &amp;lt;body&amp;gt;&#xA;    &amp;lt;div id=&amp;quot;parent&amp;quot;&amp;gt;&#xA;      &amp;lt;div id=&amp;quot;child&amp;quot;&amp;gt;&#xA;      &amp;lt;div id=&amp;quot;button&amp;quot;&amp;gt;按钮&amp;lt;/div&amp;gt;&#xA;      &amp;lt;/div&amp;gt;&#xA;    &amp;lt;/div&amp;gt;&#xA;    &amp;lt;script&amp;gt;&#xA;      window.onload = function() {&#xA;        const qId = (name) =&amp;gt; document.getElementById(name);&#xA;        const qTg = (name) =&amp;gt; document.getElementsByTagName(name)[0];&#xA;        const parent = qId(&#39;parent&#39;);&#xA;        const child = qId(&#39;child&#39;);&#xA;        const button = qId(&#39;button&#39;);&#xA;&#xA;        parent.addEventListener(&#39;click&#39;, () =&amp;gt; console.log(&#39;parent click 事件&#39;), true);&#xA;        child.addEventListener(&#39;click&#39;, () =&amp;gt; console.log(&#39;child click 事件&#39;), true);&#xA;        button.onclick = () =&amp;gt; console.log(&#39;button click 冒泡&#39;);&#xA;        button.addEventListener(&#39;click&#39;, () =&amp;gt; console.log(&#39;button click 事件&#39;), true);&#xA;&#xA;        parent.onclick = () =&amp;gt; console.log(&#39;parent click 冒泡&#39;);&#xA;        child.onclick = () =&amp;gt; console.log(&#39;child click 冒泡&#39;);&#xA;      }&#xA;    &amp;lt;/script&amp;gt;&#xA;  &amp;lt;/body&amp;gt;&#xA;&amp;lt;/html&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;首先结论是对的。&lt;/p&gt;</description>
    </item>
    <item>
      <title>sort 在 Chrome 和 Firefox 表现不同</title>
      <link>https://bigshans.github.io/post/different-sort-between-firefox-and-chrome/</link>
      <pubDate>Thu, 31 Mar 2022 10:18:10 +0800</pubDate>
      <guid>https://bigshans.github.io/post/different-sort-between-firefox-and-chrome/</guid>
      <description>&lt;p&gt;首先，这个区别不算 BUG ，因为标准并没有规定该怎么排，但这个细微区别在实现一些特殊需求时需要被注意到。&lt;/p&gt;&#xA;&lt;p&gt;注意下面一段代码：&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code class=&#34;language-javascript&#34;&gt;var a = [1, 1, 1, 1, 1];&#xA;a = a.map((k, i) =&amp;gt; ({ a: k, i: i }));&#xA;function cmp(a, b) {&#xA;  console.log(a.index, b.index);&#xA;  return a.a - b.a;&#xA;}&#xA;a.sort(cmp);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Firefox 的结果：&lt;/p&gt;</description>
    </item>
    <item>
      <title>RxJs 初探 —— 基于事件为中心的编程</title>
      <link>https://bigshans.github.io/post/rxjs-exploration/</link>
      <pubDate>Sat, 02 Oct 2021 22:19:12 +0800</pubDate>
      <guid>https://bigshans.github.io/post/rxjs-exploration/</guid>
      <description>&lt;p&gt;这是我学习 RxJs 的一些整理 ，其实 RxJs 是个 FRP 库，理解它应该从 FRP 来落脚，但一开始就讲函数式就太难了，而且放在初学者面前未免喧宾夺主了，所以我从事件开始讲，把函数式放到一边，然而这个其实也是 FRP 的重点——事件建模。&lt;/p&gt;</description>
    </item>
    <item>
      <title>使用 Sharp 压缩图片、改变图片大小</title>
      <link>https://bigshans.github.io/post/sharp/</link>
      <pubDate>Tue, 24 Aug 2021 18:20:53 +0800</pubDate>
      <guid>https://bigshans.github.io/post/sharp/</guid>
      <description>&lt;p&gt;因为业务需要就写了个图片压缩服务，顺带改变大小，因为用的是 nodejs ，于是我就选择了 &lt;a href=&#34;https://github.com/lovell/sharp&#34;&gt;sharp&lt;/a&gt; ，基于 libvips。&lt;/p&gt;&#xA;&lt;p&gt;代码非常好写：&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code class=&#34;language-javascript&#34;&gt;function resize(input, x, y) {&#xA;    return sharp(input)&#xA;        .resize(x, y, { fit: &#39;inside&#39; })&#xA;        .toBuffer();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;默认是裁剪模式，但我们要保持比例，因此用 “inside” 。因为我们还要调整一下质量，因为原始文件太大了。&lt;/p&gt;</description>
    </item>
    <item>
      <title>函数式的骨感</title>
      <link>https://bigshans.github.io/post/function-comment/</link>
      <pubDate>Tue, 24 Aug 2021 17:22:43 +0800</pubDate>
      <guid>https://bigshans.github.io/post/function-comment/</guid>
      <description>&lt;p&gt;最近读了点 rambda 的源码。函数式是个很诱人的概念，借助函数式，你可以以十分数学的方式解决一些问题。虽然如此，函数式对于现实来说仍然过于抽象，如果我们不去关注底层，那他确实是好的，然而一旦我们逼视其实现，我们就会发现它的窘迫与骨感，对于 js 来说尤是。&lt;/p&gt;</description>
    </item>
    <item>
      <title>如何写一个深拷贝函数</title>
      <link>https://bigshans.github.io/post/how-to-write-a-deep-copy-function/</link>
      <pubDate>Sun, 22 Aug 2021 14:52:42 +0800</pubDate>
      <guid>https://bigshans.github.io/post/how-to-write-a-deep-copy-function/</guid>
      <description>&lt;p&gt;跟小伙伴们讨论的时候发现，es6 的解构其实和 &lt;code&gt;Object.assign&lt;/code&gt; 一样属于是浅拷贝。那么一个深拷贝到底该怎么写呢？我个人阅读了一下 lodash 、 rambda 、 rfdc 的实现，发现思想其实都是一样，由于 rfdc 放弃了对一些内容的支持，使得它的速度飞快，但这些内容实际上我是需要的，所以 rfdc 不考虑。剩下两个实现思想基本上是一样的，但是 lodash 的实现内容很多，没有 rambda 简洁，所以我以 rambda 为蓝本自己写了一个深拷贝函数。&lt;/p&gt;</description>
    </item>
    <item>
      <title>如何编写一个 Chrome 扩展</title>
      <link>https://bigshans.github.io/post/chrome-extensions/</link>
      <pubDate>Sun, 15 Aug 2021 14:48:54 +0800</pubDate>
      <guid>https://bigshans.github.io/post/chrome-extensions/</guid>
      <description>&lt;p&gt;最近工作需要用到 Chrome 扩展，于是就特意学习了一下。起初，我以为 Chrome 扩展权限挺大，操作起来应该挺方便的，但是，实际情况各种权限需要申请，而且有些操作还要不停的绕过，写起来也是挺烦的。&lt;/p&gt;</description>
    </item>
    <item>
      <title>js 实现 DOM 监视</title>
      <link>https://bigshans.github.io/post/js-dom-watch/</link>
      <pubDate>Sun, 07 Oct 2018 15:53:19 +0000</pubDate>
      <guid>https://bigshans.github.io/post/js-dom-watch/</guid>
      <description>&lt;p&gt;花了点时间做了 b 站评论区地址链接化，比较麻烦的是 DOM 监视。找了很多，最后还是采用了 Muatation 来进行事件监视。&lt;/p&gt;&#xA;&lt;p&gt;给个文档地址：http://javascript.ruanyifeng.com/dom/mutationobserver.html 。&lt;/p&gt;</description>
    </item>
    <item>
      <title>新写了两个油猴脚本</title>
      <link>https://bigshans.github.io/post/js-tampermonkey-user-script/</link>
      <pubDate>Fri, 05 Oct 2018 13:35:27 +0000</pubDate>
      <guid>https://bigshans.github.io/post/js-tampermonkey-user-script/</guid>
      <description>&lt;p&gt;新写了两个油猴脚本针对 bilibili 。具体可以到我的 gist 上看，一个是针对番剧更新的，原本有一个番剧更新的脚本，但只是加了个标签而已，我又加了一些东西，方便查看，不过具体效果一般，而且番剧状态不能很好的体现，现没有找到好的 api 。另一个是针对 bilibili 动态的，动态不能点击链接很麻烦，于是简单写了脚本来实现将地址转换为链接。要点击进去才能有效，不过去除了带中文的链接。 bilibili 动态不能很好的选中也是一个问题，不过已经有脚本很好的实现了这个问题，所以我就不多写了。&lt;/p&gt;</description>
    </item>
    <item>
      <title>将 router 的 js 混成一个</title>
      <link>https://bigshans.github.io/post/net-musicvue-problem-set2/</link>
      <pubDate>Mon, 27 Aug 2018 17:53:56 +0000</pubDate>
      <guid>https://bigshans.github.io/post/net-musicvue-problem-set2/</guid>
      <description>&lt;p&gt;NeteaseCloudMusicApi 得重构，首先得把 router 目录下的一大堆给归拢为一个 js 方便 exports 。然而下面有九十多个文件，所以一个个复制粘贴是不现实的，更何况未来这些文件有改动，于上游一 merge ，这代码得改得老痛苦了。所以决定自己写一个小工具解决这个问题。&lt;/p&gt;</description>
    </item>
    <item>
      <title>nodejs 的 import</title>
      <link>https://bigshans.github.io/post/nodejs-es6-import/</link>
      <pubDate>Sun, 26 Aug 2018 20:29:41 +0000</pubDate>
      <guid>https://bigshans.github.io/post/nodejs-es6-import/</guid>
      <description>&lt;p&gt;nodejs 对 es 6 的支持目前并不完全，直接使用 import 不行，exports 也不行，可以用 babel 之类的编译， nodejs 10 可以尝试加上 flag ： &amp;ndash;experimental-modules。&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code class=&#34;language-shell&#34;&gt;node --experimental-modules my-app.mjs&#xA;&lt;/code&gt;&lt;/pre&gt;</description>
    </item>
    <item>
      <title>webpack 的 require 和 import 相关的一点问题</title>
      <link>https://bigshans.github.io/post/net-musicvue-problem-set1/</link>
      <pubDate>Sun, 26 Aug 2018 12:41:45 +0000</pubDate>
      <guid>https://bigshans.github.io/post/net-musicvue-problem-set1/</guid>
      <description>&lt;p&gt;今天继续用 electron-vue 写 NeteaseCloudMusic 的第三方 app， 用的 NeteaseCloudMusicApi 使用起来却很麻烦。不知道为什么之前可以正常使用，现在却不行了，摸索了好久，还是没能解决。不过还是有点收获的，接下来讲一讲。&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
