-
Notifications
You must be signed in to change notification settings - Fork 35
Constructor And Initializer
Jing Lu edited this page May 26, 2013
·
4 revisions
Actually a constructor in script is a normal function, that is, any function can create new instance when it be called using new keyword.
The syntax of constructor is same as the function:
function Apple() {
}
Usually we use first uppercase letter to identify that function will be used as constructor.
A constructor can be used to create new instance when it be called by new keyword. The 'this' keyword used in constructor will always point to the instance. For example:
function Apple() {
this.color = 'red';
}
It is same as below:
var apple = new Apple();
apple.color = 'red';
See more about Constructor.
Initializer is a syntax only available in ReoScript. Initializer used to simplify the code that merging construction and property settings. For example:
var newApple = new Apple() {
color : 'red',
price : 1.2,
};
It is same as:
var newApple = new Apple();
newApple.color = 'red';
newApple.price = 1.2;