This script is also available at .
This file contains hidden or 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
| Function.prototype.callMany = function (context) { | |
| var result = []; | |
| for (var i=1; i<arguments.length; i++) { | |
| result.push( this.call(context, arguments[i]) ); | |
| } | |
| return result; | |
| } | |
| function hi (name) { | |
| return 'Hi '+ name + '!'; |
This file contains hidden or 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
| function fib(n) { | |
| if (n==0) { | |
| return 0 | |
| } else if (n==1) { | |
| return 1 | |
| } else { | |
| return fib[n] = fib[n] || fib(n-2) + fib(n-1) | |
| } | |
| } |
This file contains hidden or 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: | |
| * 'hello {{username}}'.between('{{','}}') === 'username' | |
| */ | |
| String.prototype.between_regexp = function between(begin, end) { | |
| var regexp = new RegExp(begin + '(.+)' + end); | |
| return this.match(regexp)[1]; | |
| } |
This file contains hidden or 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
| function count(x, i) { | |
| var i = i || 1; | |
| console.log(i); | |
| if (i < x) count(x, i+1); | |
| } | |
| count(5) // 1, 2, 3, 4, 5 | |
| function count_with_depth_limit (x, start) { |
This file contains hidden or 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
| num = 1; | |
| (function () { | |
| alert(num || 2); // 1, Obviosly | |
| })(); | |
| (function () { | |
| var num = num || 2; | |
| alert(num); // 2! | |
| })(); |
This file contains hidden or 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
| function Markdown(value) { | |
| this.value = value || ''; | |
| this.length = this.value.length; | |
| }; | |
| Markdown.prototype = new String; | |
| // Instance methods | |
| Markdown.prototype.toString = Markdown.prototype.valueOf = function(){return this.value}; | |
| Markdown.prototype.toHTML = function(){return Markdown.decode(this)}; |
This file contains hidden or 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 A_reduce = [].reduce; | |
| Array.prototype.reduce = function reduce (callback, initialValue) { | |
| var operator = callback; | |
| return typeof operator == 'string' && /^[ +*/%-><!&|^?,.]/.test(operator) | |
| ? eval(this.join(operator)) | |
| : A_reduce.apply(this, arguments) | |
| }; | |
| [1,2,3,4].reduce('+') // 10 | |
| [1,2,3,4].reduce('*') // 24 |
This file contains hidden or 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-zA-Z][-+.a-zA-Z\d]*): (?# 1: scheme) | |
| (?: | |
| ((?:[-_.!~*'()a-zA-Z\d;?:@&=+$,]|%[a-fA-F\d]{2})(?:[-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]|%[a-fA-F\d]{2})*) (?# 2: opaque) | |
| | | |
| (?:(?: | |
| \/\/(?: | |
| (?:(?:((?:[-_.!~*'()a-zA-Z\d;:&=+$,]|%[a-fA-F\d]{2})*)@)? (?# 3: userinfo) | |
| (?:((?:(?:(?:[a-zA-Z\d](?:[-a-zA-Z\d]*[a-zA-Z\d])?)\.)*(?:[a-zA-Z](?:[-a-zA-Z\d]*[a-zA-Z\d])?)\.?|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[(?:(?:[a-fA-F\d]{1,4}:)*(?:[a-fA-F\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|(?:(?:[a-fA-F\d]{1,4}:)*[a-fA-F\d]{1,4})?::(?:(?:[a-fA-F\d]{1,4}:)*(?:[a-fA-F\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))?)\]))(?::(\d*))?))?(?# 4: host, 5: port) | |
| | |
This file contains hidden or 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
| >>> typeof document.all | |
| "undefined" | |
| >>> document.all | |
| [object HTMLCollection] | |
| >>> typeof document.all[0] | |
| "object" |