Javascript是否通过参考?Javascript是传递引用还是传递值?下面是一个来自JavaScript:好的部分。我很困惑my矩形函数的参数。实际上undefined,并在函数中重新定义。没有原始的参考资料。如果从函数参数中删除它,内部区域函数将无法访问它。结束了吗?但不返回任何函数。var shape = function (config) {
var that = {};
that.name = config.name || "";
that.area = function () {
return 0;
};
return that;};var rectangle = function (config, my) {
my = my || {};
my.l = config.length || 1;
my.w = config.width || 1;
var that = shape(config);
that.area = function () {
return my.l * my.w;
};
return that;};myShape = shape({
name: "Unhnown"});myRec = rectangle({
name: "Rectangle",
length: 4,
width: 6});console.log(myShape.name + " area is " + myShape.area() + " " + myRec.name + " area is " + myRec.area());
4 回答
沧海一幻觉
TA贡献1824条经验 获得超5个赞
function replace(ref) { ref = {}; // this code does _not_ affect the object passed}function update(ref) { ref.key = 'newvalue'; // this code _does_ affect the _contents_ of the object}var a = { key: 'value' };replace(a); // a still has its original value - it's unmodfiedupdate(a); // the _contents_ of 'a' are changed
慕村225694
TA贡献1880条经验 获得超4个赞
var obj = { };
obj
开满天机
TA贡献1786条经验 获得超13个赞
添加回答
举报
0/150
提交
取消