Skip to content

Instantly share code, notes, and snippets.

@sukima
Created March 5, 2014 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sukima/9369877 to your computer and use it in GitHub Desktop.
Save sukima/9369877 to your computer and use it in GitHub Desktop.
// 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