The setTimeout function, however, just has a reference to that function. When it calls it, it’s not aware of myHotDog, so JavaScript sets this to window
function HotDog() {
var my = this; // my references the current this, which is correct.
my.condiments = "mustard, ketchup";
my.getCondiments = function() {
return my.condiments; //my is guaranteed to be a reference to the original "this"
}
}
In constructors, this is always your instance. So we created a new variable, my, that references the HotDog instance. This allows you to always refer to the HotDog instance, no matter how the getCondiments function is called.
Eloquent JavaScript is a digital book providing a comprehensive introduction (tutorial) to the JavaScript programming language. Apart from a bookful of text, it contains plenty of example programs, and an environment to try them out and play with them.
The book is aimed at the beginning programmer ― people with prior programming experience might also get something out of it, but they should not read chapters 2 to 5 too closely, because most of the concepts discussed there will probably be nothing new to them. Do make sure you read the end of the first chapter, which has some essential information about the book itself.
The book is freely available, and may be used (as a whole or in parts) in any way you see fit, as long as I am credited as the original author.
A copy of the book for off-line reading can be downloaded as a zip file, and a more easily printable version can be found here.
HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser.
It has fairly good JavaScript support (which is constantly improving) and is able to work even with quite complex AJAX libraries, simulating either Firefox or Internet Explorer depending on the configuration you want to use.
It is typically used for testing purposes or to retrieve information from web sites.
HtmlUnit is not a generic unit testing framework. It is specifically a way to simulate a browser for testing purposes and is intended to be used within another testing framework such as JUnit or TestNG. Refer to the document "Getting Started with HtmlUnit" for an introduction.
HtmlUnit is used as the underlying "browser" by different Open Source tools like Canoo WebTest, JWebUnit, WebDriver, JSFUnit, Celerity, ...
HtmlUnit was originally written by Mike Bowler of Gargoyle Software and is released under the Apache 2 license. Since then, it has received many contributions from other developers, and would not be where it is today without their assistance.
The introduction of strict mode aims to avoid common coding problems in ECMAScript applications. This is achieved with the presence of a lone string literal in a unit (script or function):
"use strict;"
for either the entire script (if at the top of the script) or for a single function (if the first part of a function).
and introducing new variables through eval cannot occu
delete cannot be used against arguments, functions or variables or other properties with the configurable flag set to false
with statements, often a source of errors, are no longer used and considered syntax errors
Functions can no longer have duplicate arguments with the same name
Objects can no longer have duplicate properties with the same name
Access to the global object becomes a runtime error
A new JSON object with parse and stringify to support efficient generation of JSON data; like eval but without the security implications of being able to reduce code
Array now has standard functions, such as indexOf(), map(), filter(), and reduce()
Object now has seal()
and freeze()
Object.getPrototypeof() returns the prototype of the given object