A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.
函数与对其状态即词法环境lexical environment)的引用共同构成闭包closure)。也就是说,闭包可以让你从内部函数访问外部函数作用域。在JavaScript,函数在每次创建时生成闭包。

Read more »

Recently I have committed a big mistake: I rm my home directory. One good aspect of this bad situation is that I have backed up the code directory with borg. However, my hexo personal blog is not in the list. To make matters worse, most posts of this blog were stored locally.

Read more »

For simplicity, examples below didn’t include fancy additions like bootstrap. Only native code.

When it comes to centering an element, we would think text-align(for inline element) or margin: auto(for block element) could help with respect to viewport, but there is an edge case:

Read more »

We would choose this logic when appending element in pure javascript:

  1. 1
    2
    //locate parent tag.
    const parent_tag = document.getElementById('div_tag');
  1. 1
    2
    3
    4
    5
    // create your child tag.
    child_tag = document.createElement('a');
    child_tag.textContent="My Site";
    child_tag.setAttribute('href', `http://www.yourdomain.com`);
    child_tag.setAttribute('target', "_blank");
Read more »

你好,世界!

0%