function OtherObject(name) {
this.name = name;
this.getName = function() {alert(this.name)};
this
}
function MyObject() {
this.x = 1;
this.foo = new Array("boo","foo","fum");
this.obj = new OtherObject('Matt\'s other ojbect');
this.objArray = new Array(new OtherObject('foo object 1'), new OtherObject('foo object 2'), new OtherObject('foo object 3'));
this.objArray = new Array(new OtherObject('footy'));
var cool = "cool";
this.callInternalFunction = function() {
internalFunction();
}
internalFunction = function() {
alert('Calling an internal function and display encapsulated var cool: '+cool);
}
}
MyObject.prototype.addItem = function(item) {
this.foo[this.foo.length] = item;
}
MyObject.prototype.display = function() {
for(var i = 0; i < this.foo.length; i++) {
alert(this.foo[i]);
}
}
MyObject.prototype.displayObjs = function() {
for(var i = 0; i < this.objArray.length; i++) {
this.objArray[i].getName();
}
}
MyObject.prototype.getX = function() {
alert(this.x);
}
MyObject.prototype.displayObj = function() {
this.obj.getName();
}
var myObject = new MyObject();