tag:blogger.com,1999:blog-34454975.post642033905920782506..comments2023-06-28T16:58:41.189+02:00Comments on Web Reflection: Few JavaScript PatternsAndrea Giammarchihttp://www.blogger.com/profile/16277820774810688474noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-34454975.post-82615504911337652142011-11-18T18:32:15.565+01:002011-11-18T18:32:15.565+01:00Just to say thank you. Nice article.Just to say thank you. Nice article.Kowserhttp://kowsercse.comnoreply@blogger.comtag:blogger.com,1999:blog-34454975.post-43572494806656864752011-11-16T14:35:03.212+01:002011-11-16T14:35:03.212+01:00I should probably write another post explaining ad...I should probably write another post explaining advantages and disadvantages of each pattern ... as example module + privates can be useful but it cannot be the way all the time because it uses extra RAM, extra CPU cycles, extra redundant operations, etc etc ... if you have to create million Persons, the classic prototype approach is way better than module pattern, as example ;-)Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-16611165890230037712011-11-15T00:51:50.449+01:002011-11-15T00:51:50.449+01:00@Aadaam: try reading any philosophy after the Gree...@Aadaam: try reading any philosophy after the Greeks. Prototypes are a more advanced and natural system of modeling inheritance. The fact that the creators of so many modern languages missed it does not mean we have to go without.AutoSpongehttps://www.blogger.com/profile/11061534945724593423noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-22584660888178292652011-11-14T15:52:12.620+01:002011-11-14T15:52:12.620+01:00Function.prototype is the one inherited by all fun...Function.prototype is the one inherited by all functions so no error there, it makes you able to do whateverFuncYouWant.protectedVia(whateverClassYouWant);Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-41979724377605260522011-11-14T14:26:52.161+01:002011-11-14T14:26:52.161+01:00Can I just ask... why have you used "Function...Can I just ask... why have you used "Function" in "Function.prototype.protectedVia"? Is Function meant to be started with the uppercase (as in Function() constructor) rather than function?<br /><br />I'm a bit of a newbi to OO JavaScript.Mark Sandmannoreply@blogger.comtag:blogger.com,1999:blog-34454975.post-8452735174821000942011-11-12T17:25:10.933+01:002011-11-12T17:25:10.933+01:00@Keith H: Do take a look at AMD (Asynchronous modu...@Keith H: Do take a look at AMD (Asynchronous module definition). It allows for easy code separation and asynchronous loading and automatic dependencies handling. It seems like everyone is going that route now. Even jQuery 1.7 added AMD support. Extremely convenient as the only file that you would need to load is AMD loader (like require.js or curl.js ).Andrehttps://www.blogger.com/profile/07139169119458624452noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-12818853121768009182011-11-12T17:01:02.961+01:002011-11-12T17:01:02.961+01:00@Aadaam: agree. "Concentrate on good parts&qu...@Aadaam: agree. "Concentrate on good parts" they say, - we should always remember though that JS has many "not so good" parts and also "simply missing" parts.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-34454975.post-66122174008764680282011-11-12T15:47:13.926+01:002011-11-12T15:47:13.926+01:00I'm gonna end up working with JavaScript more ...I'm gonna end up working with JavaScript more so thanks for your post!<br /><br />JavaScript is very bendable, thats good for some but the syntax is like the Wild Wild West...The langauge lets code bandits run wild making it too easy for code to become unreadable when it lets developers write anyway they want while not including good debugging features.<br /><br />I rather work with real Classes, avoiding all the hoop jumping to emulate it. Classes make working with others as a team more efficient. They help keep the code in control...emulating theses features are worth it but still a major pain to set up most likely making more issues to debug.Keith Hhttps://www.blogger.com/profile/13419514202897247084noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-57649057917613121442011-11-12T14:31:56.060+01:002011-11-12T14:31:56.060+01:00OK, but, just by looking at it, don't you have...OK, but, just by looking at it, don't you have the urge that you need another language to generate this <b>boilerplate</b> from?<br /><br />Classical inheritance shouldn't be emulated: it should be deeply embedded into the language, writeable with the fewest characters possible.<br /><br />In real life, we don't think in prototypes: we don't think that the Berlin-Paris route is like the Berlin-London route except it goes elsewhere: we think there's a generic category of "routes" of which both are members, and we expect we can do the same things about them.<br /><br />However, it's so easy to fail to differentiate type systems and class hierarchies - look at Kevlin Henney's presentation here: http://www.infoq.com/presentations/It-Is-Possible-to-Do-OOP-in-Java<br /><br />It's nice to think in DCI-style architecture - eg. an array of POIs is one time a route, one time a list of search results, depending on context - , in real life however, a given list of POIs will be used for only one of those purposes.<br /><br />A short,easy-to-write, easy-to-read, hackless and fast class system is truly missing from javascript, no matter how we try to hide it behind idioms.Aadaamhttps://www.blogger.com/profile/05843560041038857258noreply@blogger.com