<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<script type="text/javascript">
function f(){
this.name = "test";
this.age = 13;
}
var a = f();
// 未使用 new
// window 何其冤 被增加了两个属性
console.log(a); //undefined
console.log(window.name); //test
console.log(window.age) //13
</script>
</body>
</html>
创建对象时new子的作用
最新推荐文章于 2020-11-27 04:08:26 发布