简体   繁体   中英

How do i create my own watch function similar to angular in javascript

I am a big fan of angular and loves the two-way binding concept and the watch functionality.but my present firm is using Backbone Stack and i could not find a way to include Angular JS into Backbone Stack. (If there is a way . Well and good)

I want to do some UI manipulation based on value change of a simple variable.(Need not be a object).

And If possible i want to extend it a object 1 level deep like

 var watchObj = {
   variable1 : 1,
   variable2 : 2
 }

If any of the key-value pair change i want to do some UI manipulation(Depending on the key ).

How can i achieve this with minimum possible javascript code.

I would not recommend including Angular into Backbone and if you use Backbone stack you should really go through the tutorial ( http://backbonejs.org/ ). Maybe you will find that things could be done without two-way data binding concept ( http://backbonejs.org/#FAQ-why-backbone ).

If you man by 'vanilla JS' no framework at all, then you should check Object.observe functionality ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/observe ) which not supported yet widely enough to use in production ( http://caniuse.com/#feat=object-observe ) - and thats why there are so many MVC frameworks with slightly different concepts but doing the same in the end:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM