蕭十郎
2019-05-30 10:09:16
Javascript是否通過參考?Javascript是傳遞引用還是傳遞值?下面是一個來自JavaScript:好的部分。我很困惑my矩形函數(shù)的參數(shù)。實際上undefined,并在函數(shù)中重新定義。沒有原始的參考資料。如果從函數(shù)參數(shù)中刪除它,內(nèi)部區(qū)域函數(shù)將無法訪問它。結(jié)束了嗎?但不返回任何函數(shù)。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條經(jīng)驗 獲得超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條經(jīng)驗 獲得超4個贊
var obj = { };
obj

開滿天機
TA貢獻1786條經(jīng)驗 獲得超13個贊
添加回答
舉報
0/150
提交
取消