Created
May 27, 2016 18:19
-
-
Save lfreneda/1100ecfedf7a2bec7cc527a0b0bde69c to your computer and use it in GitHub Desktop.
Underscore Omit
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
var _ = require('underscore')._; | |
var Task = (function() { | |
function Task(description) { | |
this.id = 1; | |
this.description = description; | |
} | |
Task.prototype.reportAsProblem = function(problemDescription) { | |
this.problemDescription = problemDescription; | |
}; | |
return Task; | |
})(); | |
var pkName = 'id'; | |
var task = new Task('pull request massive-js'); | |
var fieldsAndFunctions = _.omit(task, pkName); | |
console.log(fieldsAndFunctions); | |
var fields = _.omit(task, function(value, key, object) { | |
return _.isFunction(object[key]) || key === pkName; | |
}); | |
console.log(fields); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment