by S.Luann
javascript 1.3 allows to create an object from a multitude of functions, rather that just one as with javascript 1.2,
by introducing two new methods in Function object. This feature is somehow a way to implement inheritance.
function Person(){
this.name = name;
this.title = title;
}
function Programmer(){
this.skillSet = skillSet;
this.experience = experience;
Person.apply(this, arguments);
}
the only difference between call() and apply is that call needs list each single parameters.
function Person(name, title){
this.name = name;
this.title = title;
}
function Programmer(name, title, skillSet, experience){
this.skillSet = skillSet;
this.experience = experience;
Person.call(this, name, title);
}
to list all the properties of an object
var programmer = new Programmer()
foreach(int i=0; i < programmer[].length; i++){
document.writeline(programmer[i].name);
}
Handle version difference
<scritp language="javascript1.2">
by default with browsers navigator 4.01 and after, language is 1.3
Among other features that 1.3 brings, strict equal operator (===, !==), lamda expression in replace method, modified toString method, modified Boolean object, modified Array object and modified equality operator.
toString of an object
function Student(name, major){
this.name = name;
this.major = major;
}
var jenny = new Student("Jenny", "Math");
document.write(jenny.toString());
the output with 1.2:
{name:"Jenny", major:"Math"}
while with 1.3:
{object Object}
toString() method in Array
var a = new Array(1,3,4,5);
document.write(a.toString());
the output with 1.2:
[1, 3, 4, 5]
while the output with 1.3:
1,3,4,5
No comments:
Post a Comment