想仿照jquery的方法弄个$出来,写了以下js
结果g('div1')这个在火狐下报错
NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument
在stackoverflow上查到了答案
[url]http://stackoverflow.com/questions/8773579/if-javascript-has-first-class-functions-why-doesnt-this-work[/url]
原来getElementById方法中可能使用了this,这个this指的是document,
上面那样直接g = document.getElementById;this就会是global了
<script type="text/javascript">
window.onload = function() {
g = document.getElementById;
alert(document.getElementById('div1'));
alert(g('div1'));
}
</script>
结果g('div1')这个在火狐下报错
NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument
在stackoverflow上查到了答案
[url]http://stackoverflow.com/questions/8773579/if-javascript-has-first-class-functions-why-doesnt-this-work[/url]
原来getElementById方法中可能使用了this,这个this指的是document,
上面那样直接g = document.getElementById;this就会是global了