![](/img/trans.png)
[英]What is the difference between != and !== operators in JavaScript?
[英]Javascript: What is the difference between usage of . and : operators for specifying a variable in a function or object?
對於在javascript函數中使用靜態變量的方法,我發現了兩種使用的方法。 和:運算符。 使用時。 運算符,我們必須使用“ f.variable”指定變量,而在使用時:我們必須使用“ this.variable”。 這兩個運算符的用法有什么區別。
function f(){
f.a += 1;
this.b += 1;
console.log("f.a: ", f.a);
console.log("this.b: ", this.b);
}
f.a = 0;
f:b = 0;
我們也不能使用:當在函數之外使用該變量時,例如:
function g(){
f:b = 0; //this works fine.
var c = f:b; //raises error invalid label.
console.log(f:b);//but this raises an error missing ')'.
}
當我們使用var創建對象時,情況也是如此。
var obj = {
a: 2,
b: 3
}
//accessing a and b is done using obj.a & obj.b
//but here
obj:a = 4;
console.log(f.a); // this gives 2
//and similarly using obj:a as rhs value gives error.
實際如何使用這兩個運算符。
編輯:這兩種類型的變量之間有什么區別。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.