Last active
August 29, 2015 14:13
-
-
Save TomoyaShibata/c3b49969c3f25af3ce91 to your computer and use it in GitHub Desktop.
Underscore.js(lodash.js)の柴田さん独自拡張
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
(function() { | |
/** | |
* Underscore.js(lodash.js)の独自拡張 | |
*/ | |
_.mixin({ | |
/** | |
* プロパティの値が空なプロパティを削除し、新たなオブジェクトを返却します。 | |
* | |
* @param {Object} o プロパティを持つオブジェクト | |
* @return {Object} 値が空なプロパティを削除した新たなオブジェクト | |
*/ | |
compactObject: function(o) { | |
var clone = _.clone(o); | |
_.each(clone, function(v, k) { | |
if (!v) { delete clone[k]; } | |
}); | |
return clone; | |
}, | |
/** | |
* 渡された配列の持つ値が全て同一であるか否かを返却します。 | |
* | |
* @param {array} o 配列オブジェクト | |
* @return {boolean} 判定結果の真偽値 | |
*/ | |
isEqualAllValues: function(o) { | |
return _.every(o, function(v) { | |
return _.isEqual(o[0], v); | |
}); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment