*[HTML]:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>面向对象</title>
<!--单体-->
<!--<script type="text/javascript">
var tom={
name:'tom',
age:18,
showname:function () {
alert('我的名字叫'+this.name);
},
showage : function(){
alert('我今年'+this.age+'岁');
}
}
tom.showname();
tom.showage();
</script>-->
<!--工厂模式-->
<!-- <script type="text/javascript">
function Person(name,age,job){
var o = new Object();
o.name = name;
o.age = age;
o.job = job;
o.showname = function(){
alert('我的名字叫'+this.name);
};
o.showage = function(){
alert('我今年'+this.age+'岁');
};
o.showjob = function(){
alert('我的工作是'+this.job);
};
return o;
}
var tom = Person('tom',18,'程序员');
tom.showname();
tom.showage();
tom.showjob();
</script>-->
<!--构造函数-->
<!-- <script type="text/javascript">
function Person(name,age,job){
this.name = name;
this.age = age;
this.job = job;
this.showname = function(){
alert('我的名字叫'+this.name);
};
this.showage = function(){
alert('我今年'+this.age+'岁');
};
this.showjob = function(){
alert('我的工作是'+this.job);
};
}
var tom = new Person('tom',18,'程序员');
var jack = new Person('jack',19,'销售');
alert(tom.showjob==jack.showjob);
tom.showname()+tom.showage()+tom.showjob();
jack.showname()+ jack.showage()+jack.showjob();
</script>-->
<!--原型模式-->
<!-- <script type="text/javascript">
function Person(name,age,job){
this.name = name;
this.age = age;
this.job = job;
}
Person.prototype.showname = function(){
alert('我的名字叫'+this.name);
};
Person.prototype.showage = function(){
alert('我今年'+this.age+'岁');
};
Person.prototype.showjob = function(){
alert('我的工作是'+this.job);
};
var tom = new Person('tom',18,'程序员');
var jack = new Person('jack',19,'销售');
alert(tom.showjob==jack.showjob);
tom.showage=function () {
alert('我的年龄是'+this.age);
}
alert(tom.showage==jack.showage);
</script>-->
<!--继承!!!!重点-->
<script type="text/javascript">
function Fclass(name,age){
this.name = name;
this.age = age;
}
Fclass.prototype.showname = function(){
alert(this.name);
}
Fclass.prototype.showage = function(){
alert(this.age);
}
function Sclass(name,age,job) {
Fclass.call(this, name, age);
this.job = job;
}
Sclass.prototype = new Fclass();
Sclass.prototype.showjob = function(){
alert(this.job);
}
var tom = new Sclass('tom',19,'全栈工程师');
tom.showname();
tom.showage();
tom.showjob();
</script>
</head>
<body>
</body>
</html>