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 type(s) { | |
| return Object.prototype.toString.call(s).slice(8,-1).toLowerCase(); | |
| } | |
| console.assert( type( null ) == 'null', 'null' ); | |
| console.assert( type( undefined ) == 'undefined', 'undefined' ); | |
| console.assert( type( [] ) == 'array', '[]' ); | |
| console.assert( type( {} ) == 'object', 'object' ); | |
| console.assert( type( false ) == 'boolean', 'false' ); | |
| console.assert( type( 1.2 ) == 'number', '1.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
| // partial | |
| ;(function() { | |
| var BASE_FONT_SIZE = 100; | |
| var zoom = partial(function( a, b ) { | |
| return a + b; | |
| }, BASE_FONT_SIZE ); | |
| var result = zoom( -30 ); // 70 | |
| var result2 = zoom( 50 ); // 150 |
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() { | |
| //... | |
| })(); | |
| // dom 绑定. | |
| document.onclick = function () { | |
| // .... | |
| }; |
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 _name() { | |
| //... | |
| } | |
| // 函数表达式 | |
| var _name = function() { | |
| //... | |
| }; |
NewerOlder