From 6c0a60f54341b789ba1b710698b829dbf39f27d3 Mon Sep 17 00:00:00 2001
From: Michael Schreiber
- The chaining pattern is an extremely useful way to perform continuous method calls on an object in JavaScript.
-
- This pattern is widely used in many different libraries and frameworks for JavaScript.
- Starting with a value of 5, Chained methods: add(2), multiply(5), subtract(7) -> Result should be 28 {{vm.result}}
+ The chaining pattern is an extremely useful way to perform continuous method calls on an object in JavaScript.
+
+ This pattern is widely used in many different libraries and frameworks for JavaScript.
+
+ The UML Diagram is above
+ Starting with a value of 5, Chained methods: add(2), multiply(5), subtract(7) -> Result should be 28 {{vm.result}}{{vm.title}}
-
-
-
-
- Result
- {{vm.title}}
+
+
+
+
+
+ Result
+ Ql6etD0)56=tfr>Z?0rtMK@%!`d^!
z8lM}osKlzQ(qgQ_kgUrJt&h^IYuKw6(*{dW1VlgrbHONga0E9Z30z|$;wr8IQUlMr
zFS|-$je4!wx~+}kt>Eei=z1UIimoDX14Xa}j?t*onxFJKEk6JNEpk3m&?x0vui*-?
zweScCs~;!;2M$~RtZ~Vx0!y#}V6coLv5}y#)S{{vm.title}}
This pattern is widely used in many different libraries and frameworks for JavaScript.
- - The UML Diagram is above -
+ diff --git a/chaining/js/controllers.js b/chaining/js/controllers.js index fdb0fb2..58a7720 100644 --- a/chaining/js/controllers.js +++ b/chaining/js/controllers.js @@ -21,7 +21,7 @@ } else { - return new Calculator(); + return new Calculator(start); } } diff --git a/chaining/umldiagram.gif b/chaining/umldiagram.gif deleted file mode 100644 index d2c69a2e3c9f1ca2102bda7ca3d031a3bf6bcfa4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13237 zcmV;mGfK=yNk%v~VfO*>0OkMy1Ofzvf^@{ftVBXQWith the modularity of the pattern, we're able to run N visitors against our data, giving us a lot of future extensibility for our system.
- +
+ + The UML Diagram is above +
diff --git a/visitor/js/controllers.js b/visitor/js/controllers.js index 5950411..1992a85 100644 --- a/visitor/js/controllers.js +++ b/visitor/js/controllers.js @@ -2,51 +2,63 @@ 'use strict'; var Product = function(name, price, discount, sale_price){ - var self = this; + if (this instanceof Product) { + this.accept = function(visitor){ + visitor.visit(this); + }; - this.accept = function(visitor){ - visitor.visit(self); - }; + this.setDiscount = function(dis){ + discount = dis; + }; - this.getName = function(){ - return name; - }; - this.getPrice = function(){ - return price; - } - - this.setDiscount = function(dis){ - discount = dis; - }; + this.getDiscount = function(){ + return discount; + }; - this.getDiscount = function(){ - return discount; - }; + this.getDiscountPercentStr = function(){ + if(discount){ + return (discount * 100) + "%"; + } + } - this.getDiscountPercentStr = function(){ - if(discount){ - return (discount * 100) + "%"; + this.getDiscountAmount = function(){ + if(discount){ + return (price * this.getDiscount()).toFixed(2); + } } - } - this.getDiscountAmount = function(){ - if(discount){ - return (price * self.getDiscount()).toFixed(2); + this.getSalePrice = function(){ + if(discount){ + return (price * (1 - this.getDiscount())).toFixed(2); + } } - } + this.getName = function(){ + return name; + }; - this.getSalePrice = function(){ - if(discount){ - return (price * (1 - self.getDiscount())).toFixed(2); + this.getPrice = function(){ + return price; } + } + else { + return new Product(name,price,discount, sale_price); + } + + } var Discount = function(){ - this.visit = function(prod){ - prod.setDiscount(0.10); + if(this instanceof Discount) { + this.visit = function (prod) { + prod.setDiscount(0.10); + } + } + else { + return new Discount(); } + } var controllerId = "mainCtrl"; diff --git a/visitor/umldiagram.gif b/visitor/umldiagram.gif new file mode 100644 index 0000000000000000000000000000000000000000..00f369c1c7cd41eddef27f4f0c1e303915f90c0d GIT binary patch literal 40582 zcmXVWWmFtI6YkQltw0LY
zb!YCZSiJG2t69y;x@$e#UkB6UIY}9=Z}1S+7p{BRywm6EUu=8Z_x*}MtV8@;jC0$<
z&3Li-TOlW$tW_K1Q(NF;EJPq}#Ib}!n0@i_hC>iU;CGvhzgvpytV8>~=*P&
B-Oh*`34r8QSQ~X2Z`ORIcacX$B!XLmOPpASFVNyCO%9Tu+XA%o|Fo;1(1!UWHUdA@4k#&Pd}Vvp%s2v!{e{!{91U}XIdu6Ez9l~DH=@G)tPa2
za8m|}H%eCBnU_ws={b$O>*$CoDH0~kf2V!zZLgD}KS_cVQ|nTLhaaA-|+ngz=+iMHsj56Xy;6Zl0xx
z?yRk}3Fio(2YRl@_@KXZop5-hU;3nPdN>z*r}z4JH+TqF3$rc8Oq*H{THeM%jSF{q
zyichOPqu6$iKjuN)=(rv&R$%OTijN3i7)?qwQqW!aCpUkaiWL(uP^$?SNez7B2zDl
ze5N~a^Ny|OiAAsccxQak5BteC{l>Ta(uZ@V7kbBUd!_6Asmiuzs}9<4Q@5z`yx)D#
zLT46vUV}g@ZKkWgWRw$zkk8)<9_Nurk8^3~4Ts