1、//example 1
var Person = function () { };
var p1 = new Person();
= "jack";
p1.age = 25;
var p2 = new Person();
alert(); //jack
alert(); //undefined
//example 2
function CreateUser(name,qq) {
= name;
this.email = qq;
};
window.onload = function () {
obj1 = new CreateUser('a',321);
var obj2 = new CreateUser('b',123);
alert(obj1.email);
alert(obj2.email);
};
2、继承
function A(email) {
= 'a';
this.email = email;
}
A.prototype.show = function () {
alert(this.email);
};
//继承A
function B(email) {
A.call(this, email);
}
////引用赋值定义A.prototype.say B也具有say()方法
//B.prototype = A.prototype;
//B.prototype.say = function () {
// alert('My Name is '+);
//}
for (var i in A.prototype) {
B.prototype[i] = A.prototype[i]
}
B.prototype.say = function () {
alert('My Name is ' + );
}
var objA = new A('A@@.com');
var objB = new B('B@@.com');
objA.say(); //错误
















