Created
June 3, 2016 11:35
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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