function Person (name, age) {
this.name = name;
this.age = age;
}
var Mike = new Person('Mike', 24);
Person.prototype.getName = function () {// 1
return this.name;
};
Person.prototype = {// 2
foo: function () {
console.log("hello");
},
bar: function () {
console.log('world!');
}
};
console.log( Mike )// Person { name="Mike", age=24, getName=function()}
function Person (name, age) {
this.name = name;
this.age = age;
this.getName = function () {
return this.name;
};
}
function Person (name, age) {
this.name = name;
this.age = age;
};
Person.prototype.getName = function () {
return this.name;
};
function Person (name, age) {
this.name = name;
this.age = age;
this.getName = getName;
}
function getName() {
return this.name;
};