2019年12月学习内容

156 阅读1分钟

function构造器

Function 构造函数创建一个新的 Function 对象。

使用方法为:

new Function ([arg1[, arg2[, ...argN]],] functionBody)

这个地方要注意一个问题,在使用该构造器生产的函数并不会创建它们上下文中创建闭包。运行这些函数时,它们只能访问本地变量和全局变量,不能访问构造器被调生成的上下文作用域

Typescript知识点

元组Tuple

元组类型允许表示一个已知元素数量和类型的数组,各元素的类型不必相同。

x[3] = 'world'; // OK, 字符串可以赋值给(string | number)类型

console.log(x[5].toString()); // OK, 'string' 和 'number' 都有 toString

x[6] = true; // Error, 布尔不是(string | number)类型

Never

never表示那些永不存在的值的类型。

// 返回never的函数必须存在无法达到的终点
function error(message: string): never {
    throw new Error(message);
}