Based on Java coding:
public Class Dog {
int a = 1;;
int b = this.a;
public int c() {
return a+b;
}
}
Corresponding with JavaScript, we have:
function Dog() {
d = new Object();
d.a = 1;
d.b = d.a;
d.c = function() {
return this.a+this.b;
}
return d;
}
Remember in JavaScript, if variable b want to get variable a, should use d.a but not this.a, however inside method, want to get variable a, should use this.a instead of d.a.
This is a kind of JavaScript Object-oriented reliazation method.
Hi, it does not work. The Value of d.c is not 2. Why function for d.c is not working?
as the javascript, is it you called like this?
var dog = new Dog();
alert(dog.c());
?
However, I am tested in Google Chrome, haven’t tested in other browsers.