javascript - A question about the value of js variable parameters
天蓬老师
天蓬老师 2017-06-26 10:51:16
0
2
789

Saw such an article: http://www.tuicool.com/articl...
Code snippet:

<script>
function css()
{
if(arguments.length==2) //获取
{
return arguments[0].style[arguments[1]];
}
else
{
arguments[0].style[arguments[1]]=arguments[2];
}
}
window.onload=function ()
{
var op=document.getElementById('p1');
alert(css(op, 'width'));   //获取width属性值
css(op, 'background', 'green');
};
</script>
<p id="p1" style="width:200px; height:200px; background:red;"></p>

Example 2 has this line: return arguments[0].style[arguments[1]];
Why is it not written like this?
return arguments[0].style.arguments[1];
Instead of using dots, use [], array?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
ringa_lee

. When the operator accesses an attribute, the attribute name is written, and cannot dynamically generate the attribute name based on the expression. When the
[] operator accesses the attribute, can be based on [] The expression dynamically generates the attribute name and gets the attribute name string .

阿神

style.arguments[1] is equivalent to style['arguments'][1]

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template