JavaScript中valueOf()函数的用途是什么?

时间:2019-07-20 08:02:36

标签: javascript html

如果直接分配数组也给出与使用objectname.valueOf()相同的输出。 JavaScript中valueOf()的用途是什么?

var arr1 = [10, 3, 45, 14];
document.writeln("arr1: " + arr1 + "<br/><br/><br/>");

var arr2 = arr1;
document.writeln("arr2: " + arr2 + "<br/><br/><br/>");

arr2[2] = 5;
document.writeln("After change arr1: " + arr1 + "<br/>");
document.writeln("After change arr2: " + arr2 + "<br/><br/><br/>");

var arr3 = arr1.valueOf();
document.writeln("arr3: " + arr3 + "<br/><br/><br/>");

arr3[1] = 8;
document.writeln("After change arr1: " + arr1 + "<br/>");
document.writeln("After change arr2: " + arr2 + "<br/>");
document.writeln("After change arr3: " + arr3 + "<br/>");

0 个答案:

没有答案