Engineering JavaScript

2,373 views

Published on

JavaScript is a richly diverse language with a million and one approaches to solving a problem. Its flexibility can be both a blessing and a curse, but through the myriad of choices, interesting coding patterns start to emerge.

In this session, Jim Purbrick shares his own journey of discovery in JavaScript and explains the architectural patterns that he’s found useful. You are invited to share your own patterns and revelations, and we’ll compare the merits and use cases of each.

We’ll cover private methods, closures, namespaces, modules, inheritance, overloading and more.

Jim arrived at JavaScript from over a decade working with object-oriented static languages, including several years at the helm of Linden Lab‘s European headquarters in Brighton, creating technical infrastructure for the virtual world, Second Life.

Published in: Technology, Business
1 Comment
2 Likes
Statistics
Notes
  • A video of this talk is now available on blip.tv:

    <br /><object type="application/x-shockwave-flash" data="http://blip.tv/play/AYKq1y8A" width="350" height="288"><param name="movie" value="http://blip.tv/play/AYKq1y8A"></param><embed src="http://blip.tv/play/AYKq1y8A" width="350" height="288" type="application/x-shockwave-flash"></embed></object>
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
2,373
On SlideShare
0
From Embeds
0
Number of Embeds
30
Actions
Shares
0
Downloads
33
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Engineering JavaScript

    1. 1. Engineering JavaScript Dr Jim Purbrick Async 10th March 2011
    2. 2. Who Am I?Technical Director at Linden Lab Setup Linden Lab Brighton Software Engineer Musician Freelancer Entrepreneur
    3. 3. That’s No Moon...35,000 CPU CoresWeekly ReleasesNo Downtime1.5 MLOC100 Engineers10 Years Image: jurvetsonC++, Python, Perl, PHP, C#...
    4. 4. 21st Century JavaScript Image: Google Image: W3C
    5. 5. ModulemyOrg = (function(myOrg) { var myApp = myOrg.myApp = myOrg.myApp || {}; function myPrivateFunction() { // Do my thing. } myApp.myPublicFunction = function() { return myPrivateFunction(); } return myOrg;}(myOrg || {}));
    6. 6. myOrg = (function(myOrg) { Class var myApp = myOrg.myApp = myOrg.myApp || {}, myClass = myOrg.myApp.myClass = myOrg.myApp.myClass || {}; myClass.create = function() { var that = {}; myPrivateMethod() { } that.myPublicMethod = function() { myPrivateMethod(); }; return that; }; return myOrg;}(myOrg || {}));
    7. 7. InheritancemyOrg = (function(myOrg) { var myApp = myOrg.myApp = myOrg.myApp || {}, mySub = myOrg.myApp.mySub = myOrg.myApp.mySub || {}; mySub.create = function() { var that = myApp.myClass.create(), myClassMyPublicMethod = that.myPublicMethod; that.myPublicMethod = function() { // Do something. return myClassMyPublicMethod(); }; return that; }; return myOrg;}(myOrg || {}));
    8. 8. Dependency InjectionmyOrg = (function(myOrg) { var myApp = myOrg.myApp = myOrg.myApp || {}, mySub = myOrg.myApp.mySub = myOrg.myApp.mySub || {}; mySub.create = function(params) { var that = params.constructor(), myClassMyPublicMethod = that.myPublicMethod, $ = params.jQuery; that.myPublicMethod = function() { return myClassMyPublicMethod(); }; return that; }; return myOrg;}(myOrg || {}));
    9. 9. Production<script type="text/javascript">$(window).load(function() { var params, mySubInstance; params = { constructor: myOrg.myClass.create, jQuery: jQuery }; mySubInstance = myOrg.myApp.mySub.create(params); // Do something with mySubClassInstance.};</script>
    10. 10. TestJsHamcrest.Integration.QUnit();JsMockito.Integration.QUnit();test(mySubClass calls super class constructor, function () { var params, mySubInstance; params = { constructor: mockFunction(), jQuery: mockFunction() }; mySubInstance = myOrg.myApp.mySub.create(params); verify(params.constructor, once())();});
    11. 11. More?1. http://www.adequatelygood.com/2010/3/ JavaScript-Module-Pattern-In-Depth2. http://www.crockford.com/3. http://oreilly.com/catalog/97805965177484. http://docs.jquery.com/Qunit5. http://jsmockito.org/
    12. 12. Thank You!http://jimpurbrick.comhttp://18dex.com

    ×