JSFiddle - React, Tailwind, and code Playground
by lchau
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.1/lodash.js"></script>
JavaScript
_.mixin((function () {
var _result = _.result;
return {
result: function (object, property) {
var value = object ? object[property] : undefined,
args = _.rest(arguments, 2);
// Let's wrap our callback and accept any
// additional arguments passed to _.result
if (_.isFunction(value) && args.length) {
object[property] = _.wrap(value, function (func) {
return func.apply(this, args);
});
}
// Call the original _.result
return _result(object, property);
}
};
}()));
var Person = {
greeting: "Hello",
name: "Joe",
sayHello: function () {
return _.result(arguments, 0, this.greeting, this.name);
}
};
Person.sayHello(function (greeting, name) {
console.log(greeting + ' ' + name);
});