引用地址小练习

var Student=function(){};
var bosn=new Student();
Student.prototype.x='101';
Student.prototype={y:2};
console.log(bosn.x)

今天在网上看到了上面这个例子,认为console.log(bosn.x)值为undefined,bosn.y的值为2,其实不对,答案是bosn.x为101,bosn.y为undefined,原因见下图:

另外 C#中, string a = "aaaa";

                b=a;

                a="bbb";

                输出b的值仍为"aaaa",原因和这个不一样,C#的string为引用传递,但是和值传递类似,也是拷贝一份,所以值也不会改,但是和上图的原理不同(听说的,未亲自证实)

原文地址:https://www.cnblogs.com/ones/p/4673632.html