Static variable (static variable ?) :
The feature is that you can directly access it through the function name, or access it through the object instance and share it with all instances. modifications to it will affect all instances, similar to static variables sold in Java.
Instance property (instance variable ?) :
It is only valid for the current instance.
Example of static variable:
function dosum (x, y) {dosum. sum = dosum. sum + x + y; return dosum. SUM;} dosum. sum = 0; // defines static variablealert (dosum (1, 1); // result = 2 alert (dosum (1, 1 )); // result = 4var O1 = dosum (1, 1); var O2 = dosum (1, 1); alert (O1); // result = 6 alert (O2 ); // result = 8
example of instance property:
var O1 = new object (); o1.yes = true; var O2 = new object (); o2.no = false; Al ERT (o1.yes); // result = truealert (o1.no); // result = undefinedalert (o2.yes); // result = undefinedalert (o2.no ); // result = false
check whether the static method is different:
function dosum () {
}< br>
dosum. show = function () {
return "111111";
}< br>
var o = new dosum ();
alert (O. show (); // error returned: O. show is not a fun Ction
alert (dosum. show (); // result = 11111
it seems that static methods cannot be called through instances.