★创建构造函数,把事物共有的属性和方法提炼出来。构造函数名字,首字母大写。
★实例化对象分三步:
第一步:创建空对象
第二步:构造函数内部的this指向当前实例化对象
第三步:执行构造函数代码
<script>
function Score(math,chinese){
this.math=math;
this.chinese=chinese;
this.sum=function() {
console.log(this.math+this.chinese);
}
}
//实例化对象:具体的每一个事物。
//new+构造函数
var s1=new Score(100,80);
console.log(s1.math);
s1.sum();
</script>