<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="../lib/jquery-1.12.4.min.js"></script>
</head>
<body>
<script>
// 什么是实例成员:供实例使用的属性和方法就叫实例成员
// 什么是静态成员:供构造函数自己使用的属性和方法就叫做静态成员
function Person(age) {
// 这个就是实例成员
this.age = age;
}
// 这是静态成员
Person.MAX_AGE = 95;
Person.prototype={
// 给原型添加方法 这也是实例成员
run:function(){
console.log('跑');
}
}
// 问题1:实例能否使用静态成员?不能
var xm = new Person();
console.log(xm.MAX_AGE);//undefined
// 问题2:构造函数能否使用实例成员
console.log(Person.age);//undefined
Person.run();//报错
</script>
</body>
</html>
Understanding of static members and instantiated members
Guess you like
Origin blog.csdn.net/m13302979400/article/details/80755184
Ranking