HTML and CSS Reference
In-Depth Information
In Windows 8, using jQuery (and other libraries, other than the WinJs library) may sometimes
be problematic, depending on how you use the jQuery library.
The reason why jQuery can sometimes be problematic is the new security model that
Microsoft has adopted for Windows 8 applications. According to this model, dynamic
manipulation of the page structure done with data that is potentially unsafe (that is, coming
from untrusted sources) is prohibited.
If you are familiar with jQuery, you can use it as long as doing so doesn't give you a hard
time. If you are not familiar with jQuery, then it is suggested that you avoid using it for
Windows 8 applications. For most of the advanced jQuery features (such as plugins), you will
find native components in the WinJs library for Windows 8. To query elements in the hosting
HTML page, you can use HTML standard functions—such as document.querySelector —that
supports a CSS-like syntax to select elements.
practices and habits
JavaScript code is easy to make work, but definitely hard to manage and evolve, unless you set up
and adhere to a number of practices. This sole purpose of this section is to summarize the do's and
don'ts of plain JavaScript programming. “Plain” JavaScript programming means JavaScript techniques
not specifically targeted to Windows 8 development. You'll switch to focusing on specific aspects of
Windows 8 JavaScript development in the next chapter.
Group your globals
In this chapter, you learned about the need to make your global data stand out. You can achieve this
by using the following code at the top of every JavaScript file you happen to use.
var Globals = (function() { return this; }());
Suppose you have a global variable that represents the name of the application; for example, this
variable is named AppName . The purpose of the previous suggestion was so that you can use the
variable as shown below:
Globals.AppName = "MyApp";
It should be noted that AppName and Globals.AppName would point to the same location, and
both can be used in the application with the same meaning. Of course, if you consistently use the
version with the Globals prefix, you make your global variables stand out in code.
This approach is not free of issues. In particular, it still creates as many entries in the global
namespace as there are variables associated with Globals . Here's a slightly better approach: first, you
place the following code at the top of each and every JavaScript file you define.
Globals = Globals || {};
Search WWH ::

Custom Search