Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

JSOM and java script practices

2,697 views

Published on

JSOM need best practices of JQuery and Javascripts

Published in: Technology
  • Be the first to comment

  • Be the first to like this

JSOM and java script practices

  1. 1. JSOM Practices in SharePoint Melick Baranasooriya melick-rajee.blogspot.com
  2. 2. SharePoint Environment Need Environment For Connect Dlls SharePoint Client Can Use SharePoint Online Dlls SharePoint No Dll References Administrator SharePoint Client Runtime JavaScript JSOM SharePoint Development Sandbox Solutions No Need CSOM Farm Solutions SSOM Need SharePoint Environment
  3. 3.  Interpreted Language  Prototype based language JavaScript  style of object-oriented programming  Support Inheritance  Dynamic Types  Standardize as ECMAScript
  4. 4. x = "SomeName"; function Add() { x = "Add"; console.log("Add"); General Practices } //Functions is this correct ? window.Add(); //Global variables,window object console.log( window.x );
  5. 5. Window Object Window.add = function () { Window.x = “SomeName” };
  6. 6. Self-Executing Anonymous Function (function(mySpace,undefined ) { Own Namespace }( window.mySpace = window.mySpace || {}));  Check the global space for mySpace and assign a new one if not available  Leave the undefined as undefined.
  7. 7. (function(mySpace,undefined ) { //Private var x = 1; //Public Properties mySpace.y = "2"; }( window.mySpace = window.mySpace || {})); Console.log(mySpace.y) Console.log(mySpace.x) – Not accessible
  8. 8. (function(mySpace,undefined ) { //Public mySpace.add = function() { console.log("Add") }; Methods //Private function addItem( ) { console.log("AddItem") } }( window.mySpace = window.mySpace || {}));
  9. 9. mySpace.Class1 = function () { }; mySpace.Class1.prototype = { methodOne: function () { return "methodOne"; }, Classes and Objects methodTwo: function (para) { console.log(para); } }; var a = new Class1(); a.methodOne();
  10. 10.  Use Js files available in Web Server Extensions15TEMPLATELAYOUTS JSOM JavaScript Object Model
  11. 11.  SharePoint Hosted SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { // Do });  Provider Hosted JSOM <script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script> <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script> <script type="text/javascript" src="/_layouts/15/sp.js"></script>
  12. 12. Single Reference Pattern https://srj.code plex.com/
  13. 13. ? Thank You

×