作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
希望有人能帮我解决这个问题。
假设我有 2 个全局变量:var myarray=[1,3,5,7,9],hold;
然后我这样做:
function setup()
{
alert (myarray[0]);//shows 1
hold=myarray;
alert (hold);//appears to show 'hold' containing all the values of myarray. first number shown is 1
myarray[0]=2;
alert (hold);//shows the values of myarray with the updated first entry. first numbe shown is 2
}
我是否认为“保留”只是保持对 myarray 的引用,而不是实际获取 myarray 的所有值?
最佳答案
Am I to take it that 'hold' is simply keeping a reference to myarray, rather than actually taking all the values of?
不完全是,hold
和myarray
都是对同一个数组的引用。
或多或少 JS 中的所有内容都是引用(甚至 var foo = "bar"
创建对不可变字符串的引用)。
关于javascript - Js 变量引用 Quickie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9955413/
好吧,我不是 RegExpression 的专家,所以有人可以给我选择 display() 的 reg 表达式吗?和 first_name在以下 haystack 字符串中?: $Question -
希望有人能帮我解决这个问题。 假设我有 2 个全局变量:var myarray=[1,3,5,7,9],hold; 然后我这样做: function setup() { alert (myarray[
在我看来,这是一个常见的快速排序实现,该程序由一个分区子例程和两个对这些(两个)分区进行快速排序的递归调用组成。 所以控制流,在最快和最伪的伪代码中,是这样的: quicksort[list, som
我是一名优秀的程序员,十分优秀!