<script> function Person(name,age){ this.name=name; this.age=age; this.say=function(){ console.log('你好,我是'+this.name) } } var lz=new Person('lz',12) console.log(lz) </script>
new做的四件事情
1.创建了一个新的对象
2.调用了这个函数
3.让函数中国this指向这个新的对象
4.返回一个新的对象
<script> function Person(name,age){ this.name=name; this.age=age; this.say=function(){ console.log('你好,我是'+this.name) } } var lz=new Person('lz',12) console.log(lz) </script>
new做的四件事情
1.创建了一个新的对象
2.调用了这个函数
3.让函数中国this指向这个新的对象
4.返回一个新的对象
转载于:https://www.cnblogs.com/zhaodz/p/11587499.html