Skip to content

Instantly share code, notes, and snippets.

@fonzerelly
fonzerelly / get_partialRight_right_00.js
Last active September 10, 2019 19:22
simple example for the usage of lodash.js _.partial
var add = function (a, b) {
return a + b;
};
var add5 = _.partial(add, 5);
add(3,4);
// 7
add5(3);
// 8
@fonzerelly
fonzerelly / get_partialRight_right_01.js
Last active December 30, 2015 07:29
simple example of _.partialRight
var books = [
{
name: "Little Miss Sunshine",
numberOfPages: 32
},
{
name: "Mr. Strong",
numberOfPages: 36
},
{
@fonzerelly
fonzerelly / get_partialRight_right_02.js
Last active September 2, 2016 22:17
caveat of _.partialRight
_.map(books, getNumberOfPages);
// undefined, undefined, undefined
@fonzerelly
fonzerelly / get_partialRight_right_03.js
Last active September 2, 2016 22:15
reason of missbehaviour
//expected call for book[0]:
_.result(books[0], "numberOfPages");
//evaluated call:
_.result(books[0], 0, books, "numberOfPages");
//which means effectivly
_.result(books[0], 0);
@fonzerelly
fonzerelly / get_partialRight_right_04.js
Last active December 30, 2015 08:19
solution: a closure, that cuts of all surplus parameters
_.mixin(
{
"preserveCallersFirstNParams" : function (func, n) {
n = n || 0;
return function () {
return func.apply(this, Array.prototype.slice.call(arguments, 0, n));
};
}
);
var setTimeout,
clearTimeout,
setInterval,
clearInterval,
endAllTimers;
(function () {
var timer = new java.util.Timer();
var counter = 1;
var ids = {};
TextReporter.prototype = new jasmine.Reporter();
TextReporter.prototype.onRunnerFinished = function (callback) {
this.callbackEnd = callback;
};
TextReporter.prototype.reportRunnerResults = function (runner) {
// When all the spec are finished //
var result = runner.results();
@fonzerelly
fonzerelly / jasmine_on_rhino_03
Created January 19, 2014 23:21
Rhino based SpecRunner for jasmine
//Imported by Rhino on command shell
/*global load, print*/
load("lib/Timer.js");
/*global endAllTimers*/
load("lib/TextReporter.js");
/*global TextReporter*/
load("lib/jasmine-1.3.0/jasmine.js");
/*global jasmine*/
@fonzerelly
fonzerelly / high_order_classes_01
Last active August 29, 2015 13:56
A lightweight constructor for jLayout-Compunents and containers.
var _createJLayoutWrapper = function (handlePosition, predicate, getSize) {
var wrapper = {
bounds : function (value) {
if (value) {
handlePosition(value);
}
return getSize();
},
isVisible : predicate,
insets : function () {
var complexHandlePosition = function (a, b, c, d, bounds) {
...
};
//a, b are available in aVal, bVal
var easierHandlePosition = _.partial(
complexHandlePosition,
aVal,
bVal
);