Archive for September 29, 2007

JavaScript: Enumerating Properties of an Object with a For/In Loop

Posted in JavaScript, Software, programming on September 29, 2007 by Joey

JavaScript object properties can be enumerated by using a for/in loop, as demonstrated below:

var objCar = new Object();
objCar.wheels = 4;
objCar.tires = 4;
objCar.engines = 1;

for (var i in objCar)
{
document.write(i);
document.write('<br/>');
}

The result of this code is:

wheels
tires
engines

How to Create an Object in JavaScript

Posted in JavaScript, Software, programming on September 29, 2007 by Joey

An object can easily be created in JavaScript by creating a new instance of the native JavaScript Object class. Following this, properties can be assigned to it, as follows:

var objCar = new Object();
objCar.wheels = 4;

document.write(objCar.wheels);

JavaScript Instance Methods

Posted in JavaScript, Software, programming with tags on September 29, 2007 by Joey

A constructor that is created in JavaScript can have methods defined for it. These are called ‘instance methods.’

For example, suppose the following constructor was defined in JavaScript:

function Square(intSideLength)
{
this.sideLength = intSideLength;
}

In this example, ’sideLength’ is an instance property and each instantiation of the Square class will have it’s own copy of the ’sideLength’ property. Instance methods work a little differently. They are defined through the prototype property of the constructor. For example:

Square.prototype.perimeter = function() {return 4*this.sideLength;}
document.write(mySquare.perimeter());

The perimeter method is thus an instance method of the Square class. Instance methods differ from instance properties in JavaScript in that each instantiation of the instance method is shared among instantiations of the class.

Related articles:
Object-Oriented JavaScript
JavaScript Instance Properties

How to Enable and Disable JavaScript in Internet Explorer

Posted in JavaScript, Technology with tags , , on September 29, 2007 by Joey

JavaScript can easily be enabled and disabled in Internet Explorer through a check box that is found at the following location in Internet Explorer:

  • Click ‘Tools’ on the menu bar’
  • Select ‘Internet Options’
  • Click the ‘Security’ tab
  • Click the ‘Custom Level’ button
  • Scroll to the ‘Scripting’ section
    • Select ‘Disable’ to disable JavaScript
    • Select ‘Enable’ to enable JavaScript
    • Select ‘Prompt’ to be prompted whether to allow JavaScript to run on a page

Related Articles:
How to Enable and Disable JavaScript in Mozilla Firefox

What is a Mashup?

Posted in JavaScript, Software, Technology, programming with tags , on September 29, 2007 by Joey

A mashup is a web application hybrid. Mashups take information from more than one source and combine it into one application. The combination of these multiple applications makes the mashup more useful collectively than the individual applications are themselves.

A common example of a mashup is a website that uses Google Maps within its site to show visually where an address exists. So there is a web page with an address on it that becomes much more useful when another application, Google Maps, is combined with it to provide further information.

For example, see below an example from a real estate site that uses Google Maps to show the locations of local neighborhoods.

mashup