javascript 基础系列(一)

闭包:

function 内部访问外部的variables

function f(){
 alert(ysr);
}

  

报错了。

Certain language constructs block the error, for example typeof x works if there is no x (and returnsundefined), but that’s an exception.
特定的语言结构是可以阻塞(拦截)这种错误的,(不让这种错误弹出来!!)。 比如 : typeof ysr, 先用这种语言结构检测一下,就不会报错了!!

 If a variable is set, but not found anywhere, then it is created in the outmost LexicalEnvironment, which iswindow.

function f() {
  x = 5 // writing x puts it into window
}

  Decorators is a great pattern of programming, because it allows to take an existing function and extend/modify it’s behavior.

There are two reasons why decorators are cool:

  1. Decorators can be reused. The doublingDecorator can be applied to minus and divide as well assum.

  2. Multiple decorators can be combined for greater flexibility.

See the tasks below for more examples.

原文地址:https://www.cnblogs.com/oxspirt/p/5899080.html