mardi 29 mars 2016

Javascript Modules Creations

I am trying to develop a logical component that will be used in addition with other components that i plan to create. One thing i just don't get. I am sure there is a better way of doing this but i can't think of one.

var AwesomeModule = function (selector, options) {
    selector = document.querySelector(selector);
    options = options ? options : {};

    // Create Defaults
    options.name = name ? name : '';
    options.type = type ? type : '';
    options.style = style ? style : '';
    options.color = color ? color : '';

}

Is there a way to extend some of this 'default settings' without doing this pattern of checking if an item exists and if no evaluated it to an empty specific type..ex: string, object, array?

Any indications about this is highly valued

Aucun commentaire:

Enregistrer un commentaire