javascript - What are "decorators" and how are they used? -


i'm curious decorators in angularjs. there isn't information online decorators save blurb in angularjs documentation , brief (albeit interesting) mention in youtube video.

as angular guys put decorator is:

decoration of service, allows decorator intercept service instance creation. returned instance may original instance, or new instance delegates original instance.

i don't know means, , i'm not sure why separate logic service itself. example if wanted return different under different conditions pass different arguments relevant functions or use function sharing private state.

i'm still kind of angularjs noob i'm sure it's ignorance and/or bad habits i've picked up.

a use case of $provide.decorator when need minor "tweak" on third-party/upstream service, on module depends, while leaving service intact (because not owner/maintainer of service). here demonstration on plunkr.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -