JavaScript静态变量
生活随笔
收集整理的這篇文章主要介紹了
JavaScript静态变量
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
function Student(){
this.name = "khan"; //去掉this和有this的區別
this.info = function(){
alert('info()');
}
}
var student = new Student(); //創建Student對象student
document.write("對象形式1: "+student.name);
Student.name = "test"; //聲明靜態變量
document.write("靜態訪問1:"+Student.name);
var student2 = new Student(); //創建Student對象student2
document.write("對象形式2: "+student2.name);
document.write("全局變量:"+name);
1、去掉this后,name為全局變量以對象的形式將不能訪問到name的值
2、靜態變量不屬于類的某個實例對象所獨有的屬性,為對象的共享
http://www.growup-diary.com/javascript-static-variables.html
總結
以上是生活随笔為你收集整理的JavaScript静态变量的全部內容,希望文章能夠幫你解決所遇到的問題。