Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created May 10, 2013 05:27
// a default accessor for objects in js
function def(o, k, otherwise) {
return (k in o) ? o[k] : otherwise;
}
var myObject = { foo: 'bar' };
def(myObject, 'name', 'Foo');
def(myObject, 'foo', 'Blah Default');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment