Advertisement
Guest User

Untitled

a guest
Sep 8th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function makeProduct(toConvert) {
  2.     var product = {
  3.           description:'',
  4.           // ...
  5.           rules: makeRules({
  6.             onFoo(){ product.x = y; }
  7.           })
  8.         }; 
  9.     angular.extend(product, toConvert);
  10.         return product;
  11. }
  12.  
  13. function makeRules(opts){
  14.     return {
  15.         onChange: function() {
  16.             console.log("Applying global change rules: ", this);
  17.                     opts.onFoo();
  18.         },
  19.         onInstantiation: function() {
  20.             console.log("Applying instantiation rules: ", this);
  21.         },
  22.         onContextApplication: function(room) {
  23.             this.context = room;
  24.             console.log("Applying context rules: ", this, room);
  25.         },
  26.     }
  27. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement