一、认识面向对象
1.面向对象中的概念:
(1)一切事物皆对象
(2)对象具有封装和继承特性
(3)信息隐藏
二、JS面向对象
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
( function (){
var n = "yelven2"
function Person(name){
var _this = {}
_this._name = name;
_this.sayHello = function (){
alert( "PHello" +_this._name+n);
}
return _this;
}
window.Person = Person;
}());
function Teacher(name){
var _this = Person(name);
var superSay = _this.sayHello;
_this.sayHello = function (){
superSay.call(_this);
alert( "THello" +_this._name);
}
return _this;
}
var t = Teacher( "yeleven" );
t.sayHello();
|
本文转自yeleven 51CTO博客,原文链接:http://blog.51cto.com/11317783/1794385