// 定义一个对象
function Person() {
}
Person.prototype.prototypeMethod = function() {
console.log('prototypeMethod');
}
View.staticMethod = function(){
console.log('staticMethod');
}
console.log('静态方法!');
Person.staticMethod();
console.log('原型方法');
Person.prototypeMethod();// Person.prototypemethod is not a function; 因为: 原型方法只能被具体的实例调用
var person = new Person();
console.log('原型方法');
person.prototypeMethod();
console.log('静态方法');
person.staticMethod(); // TypeError: person.staticmethod is not a function
//Js 函数就是对象, Person就是对象.
// 导出整个Person对象,外边模块调用它的时候,就能够调用Person的所有方法
//(注意 Java中是Person类-> person对象(实例); JavaScript中是 Person 原型对象-> person实例)
// module.exports = Person
```
Javascript 中 对象概念 | 静态方法 | 原型方法
最新推荐文章于 2024-03-05 15:38:20 发布