Javascript中引用(與c#表現很一致)

來源:互聯網
上載者:User

Javascript中引用(與c#表現很一致)

 

js既然可以作為物件導向的程式設計語言,也具有面向對對象語言的特性

這裡說說引用的特性

 

在js中可以使用引用和c#語言表現的很一致。

執行個體1:

var obj1 = new Object()

var obj2 = obj1;

obj1.name="hello world";

alert(obj2.name == obj1.name)//會顯示是true

 

執行個體2:

var item1 = new Array('a','b','c');

var item2 = item1;

item1.push('d');

alert(item2.length)//會發現=4 和item1是一致

 

執行個體3:字串執行個體

var str1 = 'hello';

var str2 = str1;

str1 += ' world';

alert(str2);//仍然是hello。

 

這個地方的表現和c#是一致,字串對象的每次串聯或者修改都會產生新的對象,原來的對象就已經失效或者已經失去引用了

 

 

 

 

本文使用Blog_Backup未註冊版本匯出,請到soft.pt42.com註冊。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.