有些时候从引用入手可以用关联数组下标动态指定访问哪个属性:
var obj = {'name': 'hello', 'msg': 'world'};
var prop = 'name';
alert(obj[prop]);
prop = 'msg';
alert(obj[prop]);
如果找不到obj这个引用,就没法动态访问它的属性了。
另外你能解释一下下面这段脚本吗?
<script type="text/javascript">
window.F = function () {
var name = 'hello'; // new时如何绑定访问域和副本?
this.show = function () {
alert(name);
}
this.change = function () {
name = 'world';
}
}
var a = new F();
var b = new F();
a.show(); // hello
b.show(); // hello
a.change();
a.show(); // world
b.show(); // hello
</script>
【 在 withinsea (沐海~魔導奏器|歌の琴フォルテール) 的大作中提到: 】
: 那直接用不就行了?爲什麽還要從別處找引用?
--
FROM 121.33.10.*