なぜthis
が以下のコードのjsグローバルスコープを指していないのですか?コード例の `this`がjsグローバルスコープを指していない理由
<html>
<head></head>
<body>
<script type="text/javascript">
var valueHolder = {
value: '',
setValue: function(newValue) {
this.value = newValue;
},
getValue: function() {
return this.value;
}
}
valueHolder.setValue("hello world");
alert(valueHolder.getValue()); // return "hello world"
alert(valueHolder.value); // return "hello world"
alert(window.value); // return "undefined"
</script>
</body>
</html>
http://stackoverflow.com/questions/3127429/javascript-this-keyword http://www.quirksmode.org/js/this.html –