天天看點

[Javascript] Decorators in JavaScript

first, what is 'high order function', basic just a function, inside the function return another fuction.

for example:

decorators is a subset of high order fucntion:

in this code, fluent actually decorate person class, make it chainable.

but in es6:

we have no way to wrap setname and getname fucntion in fluent(). so that's way decorator comes in.

to use decorator to descorate a function in class:

and it would be nice to reuse the fluent function:

so we can do:

[note]: call(context, arguement, arguement, ....); here arguement is sinlge value

apply(context, arguements): here arguements is array

繼續閱讀