好吧,所以我有一個變量,我設置爲另一個變量,這是一個javascript對象。javascript變量引用
function Test(){
this.root = {"data":"mydata"};
}
Test.prototype.test = function(){
var current = this.root;
current = null;
console.log(this.root);
}
var t = new Test();
t.test();
我有當前指向this.root然後我重置當前爲null,但this.root仍然指向JavaScript對象。是否有可能使用當前變量將this.root設置爲null?
你只分配'null'到'current',不'this.root'。將'null'或'current'指定給'this.root'。 –
想看看這個場景,你知道'test()'裏面的'this.root',你只是簡單地爲它創建'current'類別的別名,並試圖通過它來取消'this.root'。這樣做並不意味着背後的意圖,因爲你可以只廢除'this.root'。你打算髮送'current'給某種方法,並在該方法中將其取消以使'this.root'無效?有沒有其他情況背後的具體原因試圖這樣做? – Mahesha999