日期:2014-05-16 浏览次数:20432 次
function Person(sName){
this.name = sName;
this.sayName = function(){
alert("name is " + this.name);
};
}
function Student(sName,sSubject){
this.newMethod = Person;
this.newMethod(sName);
delete this.newMethod;
this.subject = sSubject;
this.saySubject = function(){
alert("Subject is " + this.subject);
};
}
var s1 = new Student("yzl","computer science");
s1.sayName();
s1.saySubject();
function ClassZ(){
this.newMethod = ClassX;
this.newMethod();
delete this.newMethod;
this.newMethod = ClassY;
this.newMethod();
delete this.newMethod;
}
function sayInfo(sJob,sSex){
alert("My name is " + this.name + ", my job is " + sJob + ", sex is " + sSex);
}
var p1 = new Object;
p1.name = "yzl";
sayInfo.call(p1,"J2EE Developer","male");
// output: My name is yzl,my job is J2EE Developer,sex is male
function Person(sName){
this.name = sName;
this.sayName = function(){
alert("name is " + this.name);
};
}
function Student(sName,sSubject){
//this.newMethod = Person;
//this.newMethod(sName);
//delete this.newMethod;
[color=red]Person.call(this,sName);[/color]
this.subject = sSubject;
this.saySubject = function(){
alert("Subject is " + this.subject);
};
}
var s1 = new Student("yzl","computer science");
s1.sayName();
s1.saySubject();
function sayInfo(sJob,sSex){
alert("My name is " + this.name + ", my job is " + sJob + ", sex is " + sSex);
}
var p1 = new Object;
p1.name = "yzl";
sayInfo.apply(p1,new Array("J2EE Developer","male"));
// output: My name is yzl,my job is J2EE Developer,sex is male