Copying, passing, and comparing by value 的 疑惑

moliu 2009-10-21 08:00:14
var n = 1;
var m = n;
function add_to_total(total, x)

{

total = total + x;
document.write(total+"</br>");
document.write(x+"</br>")
}



add_to_total(n, m);//输出 2 和 1,
document.write(n+"</br>")//输出 1
document.write(m+"</br>")//输出 1
// 后面讲解中,提到 n=1 m=2 ,可上面的程序证明,却不是这样。请达人讲解,谢谢

附:js权威指南中的讲解
var n = 1; // Variable n holds the value 1

var m = n; // Copy by value: variable m holds a distinct value 1



// Here's a function we'll use to illustrate passing by value

// As we'll see, the function doesn't work the way we'd like it to

function add_to_total(total, x)

{

total = total + x; // This line changes only the internal copy of total

}



// Now call the function, passing the numbers contained in n and m by value.

// The value of n is copied, and that copied value is named total within the

// function. The function adds a copy of m to that copy of n. But adding

// something to a copy of n doesn't affect the original value of n outside

// of the function. So calling this function doesn't accomplish anything.

add_to_total(n, m);



// Now, we'll look at comparison by value.

// In the following line of code, the literal 1 is clearly a distinct numeric

// value encoded in the program. We compare it to the value held in variable

// n. In comparison by value, the bytes of the two numbers are checked to

// see if they are the same.

if (n == 1) m = 2; // n contains the same value as the literal 1; m is now 2
...全文
139 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
moliu 2009-10-29
  • 打赏
  • 举报
回复
if (n == 1) m = 2; // n contains the same value as the literal 1; m is now 2
//n 值确实 为 1 ,给 m 重新赋值 2,m is now 2 。原来 m 值 为 1 。
//原来是这样理解的,以为 m 的值为 2 ,是函数执行后的结果。这样的理解是错误的。
moliu 2009-10-24
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fandelei1982 的回复:]
if (n == 1) m = 2;  // n contains the same value as the literal 1; m is now 2

[/Quote]
还是不明白。为什么 m=2 ?
moliu 2009-10-21
  • 打赏
  • 举报
回复
var n = 1;
var m = n;
function add_to_total(total, x)

{

total = total + x;
document.write(total+" </br>");
document.write(x+" </br>")
}
add_to_total(n, m);//输出 2 和 1
//这如何解释?
friendly_ 2009-10-21
  • 打赏
  • 举报
回复

if (n == 1) m = 2; // n contains the same value as the literal 1; m is now 2
内容概要:本文系统研究了基于监督学习的多模态MRI脑肿瘤分割方法,重点聚焦于利用监督体素的纹理特征实现肿瘤区域的精确识别。文章首先阐述了监督学习的基本原理及多模态MRI在医学影像分析中的独特优势,进而深入探讨了灰度共生矩阵(GLCM)、局部二值模式(LBP)和小波变换等多种纹理特征提取技术。在此基础上,构建了基于传统特征工程的分类器模型以及融合深度学习的混合模型,并通过在公开数据集上的实验验证其分割性能,采用Dice系数、敏感度、特异度等指标进行全面评估。研究还剖析了当前面临的关键挑战,如高质量标注数据稀缺、模型泛化能力受限、可解释性不足以及肿瘤边界模糊等问题,进一步提出了结合半监督学习、多任务学习、模型可解释性增强及多模态信息深度融合等未来发展方向,为提升脑肿瘤自动分割的精度与临床实用性提供了系统的理论依据和技术路径。; 适合人群:具备医学图像处理或机器学习基础知识,从事生物医学工程、人工智能辅助诊断、计算机视觉等相关领域的科研人员及研究生。; 使用场景及目标:①掌握多模态MRI脑肿瘤分割中的关键技术流程与核心算法;②深入理解监督体素与纹理特征在医学图像分割中的具体应用价值;③为研发高精度、强可解释性的自动化脑肿瘤分割系统提供方法参考与技术支持。; 阅读建议:建议结合提供的Matlab代码实现同步学习,重点关注纹理特征提取与模型构建部分,动手复现实验过程以深化理解,同时重视数据预处理与结果评估环节,全面提升科研实践与创新能力。

87,986

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧