ECMAScript client object model: Implementation of the unmanaged ECMAScript client object model feels very different from the two managed client object models because of the syntax of working with objects in ECMAScript. The biggest differences between the ECMAScript client object model and the two managed client object models:
- The ECMAScript client object model’s ClientContext constructor takes zero parameters because it's locked to communicating only with the site the page is loaded from. This limitation prohibits cross-site scripting, a universally recognized security exploit.
- When writing back to SharePoint, the page that contains the ECMAScript should contain an instance of a FormDigest control to create a digest for security validation on the page.
The ECMAScript client object model has been written to not conflict with other script libraries, such as the popular jQuery and jQuery UI libraries. In fact, you can mix the use of the ECMAScript client object model and jQuery as much as you like to create robust script solutions.
To implement the ECMAScript client object model, add a single reference to the http://[..]/_layouts/sp.js file. This will add all dependent references to the page at load time. When you need to perform work with the ECMAScript client object model when the page loads, you need to make sure that the entire client object model is available and that it has been downloaded before running your code. In these cases, use the ExecuteOrDelayUntilScriptLoaded(function, library) method to call custom script functions that should be called only after the SharePoint ECMAScript library has been loaded. Figure 8 demonstrates using the ECMAScript client object model along with the popular jQuery library.
A New World
In this article, you were introduced to the three SharePoint 2010 client object models. I discussed the most important aspects and differences between each of the implementations.
You learned that you no longer have to create custom services to talk to SharePoint to satisfy your business needs. Instead, you can work with a rich API in custom .NET applications and Silverlight applications—or you can use ECMAScript for pure client-side creations.