面向对象(this的问题二)

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script>

function zgz()
{
var _this=this
this.a=5;

document.getElementById('btn').onclick=function(){

_this.show();

}
}

zgz.prototype.show=function(){

alert(this.a)

}

window.onload=function(){

new zgz();

}


</script>
</head>

<body>
<input id="btn" type="button" value="按钮">
</body>
</html>

原文地址:https://www.cnblogs.com/Greenzgz/p/4277977.html