Architecting JavaScript Code

875 views
836 views

Published on

Published in: Spiritual
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
875
On SlideShare
0
From Embeds
0
Number of Embeds
279
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • HTML5 JavaScript codeTraditional ASP.NET vs ASP.NET MVCLoad views first and get all data – talk about Windows Azure Preview Portal, pivotal trackeretcSPAWindows 8 WinRT with HTML and JavaScript
  • C:\\Users\\Suresh.Balla\\Desktop\\Win8\\Html5Demos\\2 - advanced\\C-RectanglesWithCircles.html
  • C:\\Users\\Suresh.Balla\\Desktop\\Win8\\Html5Demos\\2 - advanced\\C-RectanglesWithCircles.html
  • Architecting JavaScript Code

    1. 1. function myNonClosure() { Variable lost after var date = new Date(); function returns return date.getMilliseconds();}
    2. 2. function myClosure() { Variable stays aroundvar date = new Date(); even after function returns//nested functionreturn function () { return date.getMilliseconds(); };}
    3. 3. var calc = new Calculator(eqCtl);calc.add(2,2)
    4. 4. var Calculator = function() { //private variables //private functions return { //public members };};
    5. 5. var Calculator = function(eq) { //private member var eqCtl = document.getElementById(eq); return { var calculator = new Calculator(eq); //expose public member calculator.add(2,2) add: function(x,y) { var val = x + y; eqCtl.innerHTML = val; } };};
    6. 6. <html>... <script source="first.js"></script> <script source="second.js"></script></html>// first.js(function(ns) { // second.js ns.Customer = function() { (function(ns) { this.name = ""; ns.Order = function() { ... }; }; }(window.WilderMinds = window.WilderMinds || {}));}(window.WilderMinds = window.WilderMinds || {}));
    7. 7. <!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <title>RequireJS</title></head><body> <script src="scripts/require.js" data-main="scripts/lib/main.js"> </script></body></html>
    8. 8. // main.jsrequire(["Customer"], // Requires the Customer Module function (Customer) { // Call with required Module(s) // Your Initialization Code var c = new Customer("A Customer"); var name = c.name; } );
    9. 9. // Customer.jsdefine( [], // Required Scripts (None) function(){ // Gets any required modules here like main function Customer (name) { this.name = name } return Customer; // Return the object that Requires //constructor to allow you to call it}
    10. 10. Suresh.Balla@neudesic.com

    ×