<script type= "Text/javascript" ></script>
<script type= "Text/javascript" >
function Student (name,age) {
This.name=name;
This.age=age;
}
student.hello= "Hello World";
Student.prototype.sayhello=function () {
Return this.name+ "--" +this.age+ "--" +student.hello;
};
var stu=new Student ("Zhang San", "14");
Alert (Stu.sayhello ());
</script>
<script type= "Text/javascript" >
var Student =function () {
var obj=new Object ();
obj.hello= "Hello World";
Obj.sayhello=function (name,age) {
Return name+ "--" +age+ "--" +this.hello;
}
return obj;
}
var stu=new Student ();
Alert (Stu.sayhello ("John Doe", "15"));
</script>
<script type= "Text/javascript" >
var student=new Object ();
student.hello= "Hello World";
Student.sayhello=function (name,age) {
Return name+ "--" +age+ "--" +this.hello;
}
Alert (Student.sayhello ("Harry", "16"));
</script>
<script type= "Text/javascript" >
var student={
Hello: "Hello World",
Sayhello:function (name,age) {
Return name+ "--" +age+ "--" +this.hello;
}
};
Alert (Student.sayhello ("Zhao Liu", "17"));
</script>
<script type= "Text/javascript" >
var student=new Function ("this.hello=\" helloworld\ "; this.sayhello=function (name,age) {return name+\"--\ "+age+\"--\ "+this.hello;}");
var stu=new Student ();
Alert (Stu.sayhello ("Chen Qi", "18"));
</script>
JS Object-oriented practice