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.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值