<form> <input id="text" type="text"/> <input id="btn" type="button" value="button"/> </form> <script> document.getElementById("btn").onclick = function(){ var value = document.getElementById("text").value; alert(value); } document.getElementById("btn").onclick = (function(){ var input = document.getElementById("text"); return function(){ alert(input.value); } })(); function A(){ var name = "a"; this.getName = function(){ reutrn name; } this.setName = function(_name){ name = _name; } } </script>
<script> var fun = function(){ var num = 0; return { call:function(){ alert(num++); }, reset:function(){ num=0; } } }(); var obj = { num:0, call:function(){ alert(this.num++); }, reset:function(){ num=0; } }; obj.call(); alert(obj.num); obj.reset(); alert(obj.num); </script>