Basics: Imperative vs Declarative

We just created a WinJS control declaratively - using markup in HTML to create controls. We can also create WinJS controls imperatively in the JavaScript file.

How to create a WinJS Rating control:

   data-win-options={maxRating:10}> </div>
var myDiv = document.createElement("div");
var newControl = new WinJS.UI.Rating( myDiv, { maxRating: 10 });

Imperative constructors take two arguments, both optional. The first is the DOM element on which to construct the control. In the example above, we passed it the div we just created. The second argument is an object representing the configuration of the control, formatted using the same syntax for we used with data-win-options. WinJS supports both imperative and declarative methods, though in this tutorial, we will mostly use declarative syntax.