Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ovdojoey/b198252feb03531c2b051f8f50834900 to your computer and use it in GitHub Desktop.
Save ovdojoey/b198252feb03531c2b051f8f50834900 to your computer and use it in GitHub Desktop.
A way to pass in options to a function to override default options
function MyCoolThing(options) {
// default options
this.options = {
feature: false,
timeOut: 4000,
title: 'Feature title'
};
// override default options
if ( typeof options !== 'undefined' ) {
for ( prop in options ) {
if ( prop in this.options ) {
this.options[prop] = options[prop];
}
}
}
}
var sweet = new MyCoolThing({
feature: true,
timeOut: 2000
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment