HTML and CSS Reference
In-Depth Information
for(vari=0,l=fixes.length; i < l; i++) {
property = fixes[i];
if (tddjs.isOwnProperty(object, property)) {
callback(property, object[property]);
If we change the for-in loops in the tests in Listing 7.11 to use the new
tddjs.each method, the tests will run, even on Internet Explorer. Addition-
ally, the method smoothes over a similar bug in Chrome in which function objects
prototype property is not enumerable when shadowed.
7.2 Creating Objects with Constructors
JavaScript functions have the ability to act as constructors when invoked with the
new operator, i.e., new MyConstructor() . There is nothing that differentiates
the definition of a regular function and one that constructs objects. In fact, JavaScript
provides every function with a prototype object in case it is used with the new
operator. When the function is used as a constructor to create new objects, their
internal [[Prototype]] property will be a reference to this object.
In the absence of language level checks on functions vs. constructors, con-
structor names are usually capitalized to indicate their intended use. Regardless of
whether you use constructors or not in your own code, you should honor this idiom
by not capitalizing names of functions and objects that are not constructors.
7.2.1 prototype and [[Prototype]]
The word “prototype” is used to describe two concepts. First, a constructor has
a public prototype property. When the constructor is used to create new ob-
jects, those objects will have an internal [ [Prototype]] property that is a refer-
ence to the constructor's prototype property. Second, the constructor has an
internal [[Prototype]] that references the prototype of the constructor that cre-
ated it, most commonly Function.prototype . All JavaScript objects have
an internal [[Prototype]] property; only function objects have the prototype
Search WWH ::

Custom Search