Skip to content

Instantly share code, notes, and snippets.

@mmaelzer
mmaelzer / gist:92570feecd925d8eb827
Created September 23, 2014 19:51
Logging on an object's methods
var protos = Object.getPrototypeOf(this);
Object.keys(protos).forEach(function(key) {
if (typeof this[key] === 'function' && key !== 'constructor') {
var fn = this[key];
this[key] = function() {
var name = this.name ? this.name + '.' : '';
var identity = name + key;
console.time(identity);
var ret = fn.apply(this, arguments);
console.timeEnd(identity);
@mmaelzer
mmaelzer / gist:5945996
Created July 8, 2013 03:18
jQuery - get percentage scrolled from top/bottom
$.fn.percentScrolledTop = function() {
var vals = [];
this.each(function() {
vals.push(+($(this).scrollTop() / this.scrollHeight));
});
return vals.length === 1 ? vals[0] : vals;
};
$.fn.percentScrolledBottom = function() {
var vals = [];