Generating Pre Initialised Object

thepian edited this page Nov 17, 2011 · 1 revision

By default a generated object starts out blank before the constructors are called. You can fill in member variables with argument values. This will seed the members before the base constructors are called.

function Rectangle(width,height) {}
Rectangle.arguments = [
    NumberType({ name:"width", preset:true }),
    NumberType({ name:"height", preset:"height" })

If an argument is configured with a preset attribute the argument will be used to assign the member variable before the constructors are called. A name can be specified or true for the argument name.

For base constructors you may have a different set of parameters than the main.

function Square(size) {}
Square.arguments = [
    NumberType({ name:"size", alias: { "width": true, "height": true } })

Here the size argument will be passed to the Rectangle constructor under the names width and height. If you need to change the value you can supply a function instead of true.

The above is equivalent to:

function Init() {
    if (this instanceof Square) {
        this.width = this.height = size;

function Rectangle(width,height) {

function Square(size) {

You can’t perform that action at this time.
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.
Press h to open a hovercard with more details.