js 使用call方法传递window对象
匿名函数使用.call(this)方法就可以传递window对象到当前函数中。
<script type="text/javascript">
var cid = 1;
var width = 120;
var height = 400;
</script>
<script type="text/javascript">
(function(){
console.log(this.cid);
console.log(this.width);
console.log(this.height);
console.log(this);
}).call(this);
</script>
参考:
https://stackoverflow.com/questions/6287511/reason-behind-this-self-invoking-anonymous-function-variant