Skip to content

Instantly share code, notes, and snippets.

@henriquegogo
Last active September 23, 2019 20:23
Show Gist options
  • Save henriquegogo/6c442b476279732336e0 to your computer and use it in GitHub Desktop.
Save henriquegogo/6c442b476279732336e0 to your computer and use it in GitHub Desktop.
Get all elements with id and return as a object model
var viewModel = [].reduce.call(document.querySelectorAll('[name]'), function(result, i) {
return Object.defineProperty(result, i.name, {
get: function() { return i.value },
set: function(value) { i.value = value },
configurable: true
});
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment