function createPerson (name,age) {
var o = new Object ();
o.name = name;
o.age = age;
o.say = function () {
console.log('My name is ' + this .name + "; my age is " + this .age + '.' );
}
return o;
}
var sqf = createPerson('shaoqianfei' ,22 );
sqf.say();
console.log(sqf instanceof Object );
console.log(sqf instanceof createPerson);
function Person (name,age) {
this .name = name;
this .age = age;
this .say = function () {
console.log('My name is ' + this .name + "; my age is " + this .age + '.' );
};
}
var person1 = new Person('liuxiang' ,23 );
var person2 = new Person('liuxiang2' ,24 );
person1.say();
console.log(person1 instanceof Object );
console.log(person1 instanceof Person);
console.log(person1.say == person2.say);
console.log("模式三:原型模式,我们先看看之前的原型是怎样的" );
console.log(Person.prototype.isPrototypeOf(person1));
console.log(Object .getPrototypeOf(person1) == Person.prototype);