Created
March 5, 2014 15:50
-
-
Save sukima/9369877 to your computer and use it in GitHub Desktop.
This file contains 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
// My object err.. function, ya know. | |
function MyObject(options) { | |
if (!options) { | |
options = {}; | |
} | |
var default_options = { | |
foo: 'foo', | |
bar: 'bar' | |
}; | |
// Do awesome magic stuff here... | |
// ( With libs: $.extend(), _.extends() ) | |
// However, I want it without libs. And allowed with IE8. | |
// I'd preffer a pattern over a polyfill function | |
// | |
this.options = default_options << options; // fill in the blanks here. | |
} | |
// I'd use it like so: | |
var a = new MyObject(); | |
var b = new MyObject({foo: 'foobar'}); | |
var c = new MyObject({foo: 'foobar', bar: 'barfoo'}); | |
a.options; // => {foo: 'foo', bar: 'bar'} | |
b.options; // => {foo: 'foobar', bar: 'bar'} | |
c.options; // => {foo: 'foobar', bar: 'barfoo'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment