HTML and CSS Reference
In-Depth Information
This object simply exposes methods that allow you to add or remove the active
class name from an element with a specific ID. There is also a method to
facilitate hiding all cards within the deck. The _cards instance variable holds a
list of all cards within the deck.
As you can see, rather than creating an anonymous function, the function itself
is wrapped in parentheses, and the function itself returns an object with
methods. This is known as the revealing module pattern. It differs from the
normal way of creating objects in JavaScript by creating a function and using
this.methodName to create methods. The code within the function is
automatically executed when the script loads, and returns an object.
var myObject = (function(){
return {
sayHi: function(){
This means that you don't have to create a new object using the new operator.
You can simply call the object by using its assigned variable ( myObject , in this
case), as the constructor has already executed. You can then access the
''public'' methods in much the same way as any object.
The downside to this method is that there is no obvious way to create a new
object and assign it to a new variable.
Sending Cross-Site Requests
There might be times when you need to pull in data from external web services
other than your own. To do this, you would normally use Ajax. If the other server
supports Cross-Origin Resource Sharing (CORS), you will be able to make
remote Ajax requests. Unfortunately, not all web services support this.
To get around this issue, some web services support JSONP. JSONP allows
you to send a callback parameter to a web service. Normally, you'll receive a
JSON object as part of a JSON request much like the following.
Search WWH ::

Custom Search