person1 = new Object(); person1.firstName = " Frodo "; person2 = new Object(); person2.firstName = " Zarg "; var tt = function(e) {document.write(e+this.firstName + "<->" + firstName);} person1.sayName = tt; person2.sayName = tt; person1.sayName(" 1"); person2.sayName(" 2"); var firstName = "MainLine"; tt(" 3");
This style of object fails to abstract the values inside the object. Function tt was able to get the value “Zarg” thru a peculiar and undocumented interpretation of “person2.sayName(" 2")” which means something different from “(person2.sayName)(" 2")”. But there is a better way.