Last active
August 29, 2015 13:57
-
-
Save kevin-lee/9915562 to your computer and use it in GitHub Desktop.
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 logger = console ? console : { | |
"log": function() { | |
// It does nothing. | |
} | |
}; | |
/** | |
* Number.prototype.format(n, x, s, c) | |
* | |
* @param integer n: length of decimal | |
* @param integer x: length of whole part | |
* @param mixed s: sections delimiter | |
* @param mixed c: decimal delimiter | |
*/ | |
Number.prototype.format = function(n, x, s, c) { | |
var regex = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\D' : '$') + ')', | |
num = this.toFixed(Math.max(0, ~~n)); | |
return (c ? num.replace('.', c) : num).replace(new RegExp(regex, 'g'), '$&' + (s || ',')); | |
}; | |
/** | |
* It returns a function that binds the given function with the given context and runs it. | |
* e.g.) | |
* function enclosing() { | |
* this.name = "Kevin"; | |
* var $someElem = $('#someElem'); | |
* $someElem.on('click', _bind_(function(event) { | |
* event.preventDefault(); | |
* $someElem.val(this.name); // this is now the enclosing function object. | |
* }, this)); | |
* } | |
* @param function fn | |
* @param Object theContext | |
*/ | |
var _bind_ = function _bind_(fn, theContext) { | |
return function() { | |
return fn.apply(theContext, arguments); | |
}; | |
}; | |
var makeClickable = function makeClickable(selector, callback) { | |
$(selector).on('click', function(event) { | |
callback.call(this, event); | |
}).css('cursor', 'pointer'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment