Javascript是通过引用传递还是通过值传递?以下是Javascript:Good Parts的示例.我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"
}); …Run Code Online (Sandbox Code Playgroud)