日期:2014-05-16 浏览次数:20508 次
// Define a so called class
var person = function() {
this.name = "vulnerability";
this.age = 28;
}
// Instantiate the class
var p1 = new person();
alert(p1.age);
var man = function() {
this.show = function() {
alert("The man is showing himself");
}
}
// Let the man extend the person
man.prototype = p1;
// Instantiate the man class
var m1 = new man();
// Invoke the show method
m1.show();
alert(m1.name);
// Set the property of the instance of subclass m1.name = 'susceptibility'; // Verify whether the property has been set to the instance alert(m1.name); // Verify whether the property of the instance of prototype // has been modified alert(p1.name);
// Set the property of the prototype of man man.prototype.name = 'changed value'; // The property of the instance of subclass wouldn't be changed alert(m1.name); // The property of the prototype has been changed alert(p1.name);