mardi 23 février 2021

How Kyle Simpson's OLOO Pattern handles a not initializated object?

Suppouse the next example extracted from another OLOO question:

var Foo = {
    init: function(who) {
        this.me = who;
    },
    identify: function() {
        return "I am " + this.me;
    }
};

Here, I want to throw an error or deny the call of identify if the object was not initialized before call the function. However, I dont want to add a verifier inside each public routine of the Object.

How can I handle it without duplicating that behaviour?

Aucun commentaire:

Enregistrer un commentaire