JS March 02, 2018

5分钟上手TypeScript

Words count 5.1k Reading time 5 mins.

有两种主要的方式来获取TypeScript工具:

  • 通过npm(Node.js包管理器)
  • 安装Visual Studio的TypeScript插件

Visual Studio 2017和Visual...

Read article

JS March 02, 2018

5分钟上手TypeScript

Words count 5.1k Reading time 5 mins.

有两种主要的方式来获取TypeScript工具:

  • 通过npm(Node.js包管理器)
  • 安装Visual Studio的TypeScript插件

Visual Studio 2017和Visual Studio 2015 Update 3默认包含了TypeScript。 如果你的Visual Studio还没有安装TypeScript,你可以下载它。

针对使用npm的用户:

npm install -g typescript

在编辑器,将下面的代码输入到greeter.ts文件里:

function...
Read article

JS February 27, 2018

JavaScript奇技淫巧44招

Words count 19k Reading time 17 mins.

原文地址


变量没有声明而直接赋值得话,默认会作为一个新的全局变量,要尽量避免使用全局变量。

==和!=操作符会在需要的情况下自动转换数据类型。但===和!==不会,它们会同时比较值和数据类型,这也使得它们要比==和!=快。

[10] === 10    // is false
[10]  == 10    // is true
'10' == 10     // is true
'10' === 10    // is false
 []   == 0     // is true
 [] ===  0     /...
Read article

JS February 26, 2018

10个最佳ES6特性

Words count 7k Reading time 6 mins.

原文地址

ES6,正式名称是ECMAScript2015,但是ES6这个名称更加简洁。ES6已经不再是JavaScript最新的标准,但是它已经广泛用于编程实践中。如果你还没用过ES6,现在还不算太晚…

不使用ES6
为函数设置默认值

function foo(height, color)
{
    var height = height || 50;
    var color = color || 'red';
    //...
}

这样写一般没问题,但是,当参数的布尔值为false...

Read article

JS February 24, 2018

只有20行Javascript代码!手把手教你写一个页面模板引擎

Words count 1.1k Reading time 1 mins.

原文地址

var TemplateEngine = function(html, options) {
    var re = /<%([^%>]+)?%>/g, reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g, code = 'var r=[];\n', cursor = 0; //正则捕获所有以<%开头,以%>结尾的片段
    var add = function...
Read article
0%