Skip to content

Might be worth testing ( simpler/safer initialisation of parameters ) ? #286

Description

@Snky
    /**
     * Hello guys! This works fine for me, even for the booleans,
     * not sure if there was a special reason for setting booleans manually
     * No errors can be thrown now, if the property doesn't exist on the object
     * thanks to the "in" bit, works better than hasOwnProperty(param)
     */
    public function setParams(object : Object, params : Object) : void {
        var param : String;
        for (param in params) {
            if (param in object) object[param] = params[param];
        }
    }


    /**
     * The initialize method usually calls this.
     */
    public function setParams(object : Object, params : Object) : void {
        for (var param : String in params) {
            try {
                if (params[param] == "true")
                    object[param] = true;
                else if (params[param] == "false")
                    object[param] = false;
                else
                    object[param] = params[param];
            } catch (e : Error) {
                if (!hideParamWarnings)
                    trace("Warning: " + e.message + " " + this);
            }
        }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions