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
// The supershort version | |
// with no polyfills or extras (as super, named constructors etc.) | |
// And nice way to handle inheritance is by creating a base object | |
// with an extend method | |
var Base = { | |
extend: function(props){ | |
// A new object with this object as its prototype | |
var obj = Object.create(this); | |
// Assign properties to the new object |
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
// First things first - polyfills for IE | |
// Thomas' minimal Object.assign polyfill | |
Object.assign = Object.assign || function(){ | |
for(var i = 1; i < arguments.length; i++){ | |
for(var j in arguments[i] || {}){ | |
arguments[0][j] = arguments[i][j]; | |
} | |
} | |
}; |
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 propSearch = (function(){ | |
/* | |
ironboy, Jan 2016 | |
Search an endlessly deep/complex JS data structure with ease | |
Call this function with a search object as your input parameter. | |
searchObj: |
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
// A cool JSON reviver | |
// Thomas Frank 2015 | |
// MIT licensed | |
JSON.cool = (function(){ | |
var mem, findMem, base, toFind, settings = { | |
circulars: true, | |
dates: true, | |
functions: false, |
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
if ( typeof Object.getPrototypeOf !== "function" ) { | |
if ( typeof "test".__proto__ === "object" ) { | |
Object.getPrototypeOf = function(object){ | |
return object.__proto__; | |
}; | |
} else { | |
Object.getPrototypeOf = function(object){ | |
// May break if the constructor has been tampered with | |
return object.constructor.prototype; | |
}; |
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
Object.slice = function(){ | |
var | |
args = [].slice.call(arguments), | |
obj = args.shift(), | |
obj2 = {}, | |
keys = Object.keys(obj); | |
keys.slice.apply(keys,args).forEach(function(x){ | |
obj2[x] = obj[x]; | |
}); | |
return obj2; |
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
Number.prototype.slice = function(x,y){ | |
return (this+'').slice(x,y)/1; | |
} |
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
$scope.changeWatch = function(){ | |
// An alternative to Angular $scope.$watch | |
// that does not trigger on initial load | |
var | |
init = true, | |
args = [].slice.call(arguments), | |
listener = args[1]; |
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
// options object example | |
/* | |
{ | |
decimals:2, | |
decimalSign:",", | |
thousandSep: " ", | |
currency:"SEK" | |
} | |
*/ |
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
// Example usage niceFormat | |
// new Date().niceFormat('yyyy-mm-dd hh:ii:ss') | |
// Example usage countdown | |
// new Date().countdown(dateInFuture,'ii:ss') | |
// try with new Date().countdown(new Date(new Date().getTime()+3600000),"ii:ss") | |
(function(){ | |
var a = { |