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-when implementation on ES5 (made by afonsomatos) | |
Released under the MIT license (2014-11-10) | |
*/ | |
// object.when | |
Object.defineProperty(Object.prototype, "when", { |
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
// Most accurate javascript timing | |
now = function() { | |
return performance.now()|| | |
performance.mozNow() || | |
performance.msNow() || | |
performance.oNow() || | |
performance.webkitNow() || | |
Date.now() || | |
new Date().getTime(); |
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
// Get script file location | |
// doesn't work for older browsers | |
var getScriptLocation = function() { | |
var fileName = "fileName"; | |
var stack = "stack"; | |
var stackTrace = "stacktrace"; | |
var loc = null; | |
var matcher = function(stack, matchedLoc) { return loc = matchedLoc; }; |
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
/*! | |
* Easy to use table creator | |
* afonsomatos <[email protected]> | |
* | |
* @param {Array} - Array containing the rows of the table | |
* @param {Object} [{rows: Array.length, | |
* padding: 2, | |
* marginLeft: 2, | |
* lineHeight: 0, | |
* cols: <row in most length>.length }] - Configure 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
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> | |
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> | |
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> | |
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> | |
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> | |
<colorful>YOU HAVE WON CLICK FOR PRIZE</colorful> <BR> |
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
// Octals 0 + o + integer | |
0o8 | |
// Binary 0 + b + integer | |
0b11 | |
// ParseInt doesn't support binary literals | |
parseInt('0b11', 2); // 0 | |
// Instead use Number() | |
Number('0b11'); // 3 | |
// Or remove prefix | |
parseInt('11', 2); // 3 |
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
// Get sign of number (-1, +1) or NaN or (-+)zero | |
Math.sign(-8); // -1 | |
Math.sign(2); // 1 | |
Math.sign(0); // 0 | |
Math.sign(-0); // -0 | |
Math.sign(NaN); // NaN | |
// Remove decimal fraction of x | |
Math.trunc(Math.PI); // 3 | |
Math.trunc(-3.99999); // -3 | |
// Cube root of x |
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 strings starts with substr | |
'myString'.startsWith('my', 0 /* start searching */); // true | |
// If string ends with substr | |
'myString'.endsWith('ring', 8 /* end searching */); // true | |
// If strings has another substr | |
'myString'.includes('str', 0 /* start searching */); // true | |
// Multiply string | |
'woof '.repeat(5); | |
// -- Template strings | |
// String interpolation |
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
// Primitive value | |
typeof Symbol(); // 'symbol' | |
// Unique | |
Symbol() === Symbol(); // false | |
// Invoked without `new` | |
new Symbol(); // TypeError: Symbol is not a constructor | |
// Set description of Symbol | |
let sy = Symbol('personal primitive'); | |
String(sy); // 'Symbol(personal primitive)' | |
// Symbols as property keys and method names |
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
// Template strings | |
`Hello my name is ${firstName} ${lastName}` | |
// Mult-line | |
`This is a multi-line | |
string that appears | |
to be very cool perhaps | |
it is.` | |
// Tagged template | |
tagFunction`Hello\n ${firstName} ${lastName}` | |
// Implement tagFunction |
OlderNewer