Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Snky opened this issue Jul 11, 2016 · 1 comment
Open

Comments

@Snky
Copy link

Snky commented Jul 11, 2016

    /**
     * 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);
            }
        }
    }
@Snky
Copy link
Author

Snky commented Jul 11, 2016

Well, either way, if there are good reasons for the way it's implemented, I think the "(param in object)" bit will help, you can throw thousands of parameters at the object then, and it will just ignore those properties if they are not present in that class.

-edit-
After further testing, it does not seem to pick up all the variables within a class, probably unstable then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant