You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jing Lu edited this page May 26, 2013
·
4 revisions
Constructor
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:
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;