SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 107 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"

Shallow inheritance means that
you might have a class inherit from another class, and that??™s it. JavaScript was never designed
to allow for deep inheritance. The need for deep inheritance in JavaScript is less likely.
For more information on deep inheritance, check out the following:
??? Classical Inheritance in JavaScript, by Douglas Crockford (http://javascript.
crockford.com/inheritance.html)
??? Base, by Dean Edwards (http://dean.edwards.name/weblog/2006/03/base/)
Object Literals
Using an object literal is the other primary way of creating a new object. It??™s also dirt simple
to do:
var customObject = {};
That??™s it; you now have an object. Extending your object with its own properties and
methods is straightforward as well:
var customObject = {
customProperty: 5,
customMethod: function(){ /* using an anonymous function*/ }
};
Each property contains a key-colon-value combination, and each declaration is separated
by a comma. Key names get converted into strings internally. For the most part, this
doesn??™t matter, but you can actually do some neat things if you know about it. The following
is completely valid:
var customObject = {
"My custom property": 5,
5:6,
"5":7
};
Keep in mind that because the keys get converted to strings, the second "5" would actually
overwrite the first 5, leaving your customObject["5"] with a value of 7.
If you use special characters such as spaces, or if the property name starts with a number,
the only way to access those properties is through bracket notation or by looping through all
properties using a for.


Pages:
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
Free English grammar and study guid Russian bride druga wojna światowa counter strike 1.6 hotel jelenia góra