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
| /** | |
| * 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 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
| 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
| 'wrath, greed, sloth, pride, lust, envy, and gluttony'.match(/greed.+/) | |
| #<MatchData "greed, sloth, pride, lust, envy, and gluttony"> | |
| 'wrath, greed, sloth, pride, lust, envy, and gluttony'.match(/greed.+?/) | |
| #<MatchData "greed,"> |
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
| // ==UserScript== | |
| // @name ligatweet | |
| // @namespace http://leaverou.me/demos/ligatweet/ | |
| // @description Script for tweet shortening using unicode ligatures and other compound symbols | |
| // @include htt*://twitter.com/* | |
| // @author Lea Verou (UserJS by Nikita Vasilyev) | |
| // @version 1.0 | |
| // @license Licensed under the MIT license http://www.opensource.org/licenses/mit-license.php | |
| // ==/UserScript== |
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 f(){/* comment */} | |
| alert(f+''); | |
| // Opera, IE, Chrome: function f(){/* comment */} | |
| // Firefox, Safari: function f(){} | |
| // | |
| // Note: in Firefox: f+'' === f.toSource() |
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
| // JS Events API sucks. addEventListener ugly. If I'll design this API from scratch, I've done this: | |
| window.events // {} | |
| window.events.load // [] | |
| window.events.load.length // 0 | |
| window.events.load.push(function(e){ | |
| alert('window loaded') | |
| }) | |
| window.events.load.length // 1 |