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 a = { | |
b:function() { console.log(this); } | |
} | |
//求下面的输出 | |
a.b(); | |
c = a.b(); | |
(1, a.b)(); | |
(a.b)() |
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 connect = require('connect'); | |
var port = parseInt(process.argv[2]) || 3000; | |
var app = connect() | |
.use(connect.logger('dev')) | |
.use(connect.static(__dirname)) | |
.use(connect.directory(__dirname)) | |
.use(function(req, res){ | |
res.end('wrong url\n'); | |
}) | |
.listen(port); |
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
(function(window) { | |
var document = window.document; | |
var loadScript = function(uri) { | |
var script = document.createElement('script'); | |
script.src = uri; | |
document.querySelector('head').appendChild(script); | |
}; | |
window.loadScript = loadScript; | |
})(window) |
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
(function(window) { | |
if (window.Float32Array) return; | |
var unsigned = 0; | |
var signed = 1; | |
var floated = 2; | |
function TypedArray(klass, arg, offset, length) { | |
var a, b, bits, i, imax; | |
if (Array.isArray(arg)) { |
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
function getAttrSafe(obj, keyChain, delimiter) { | |
delimiter = delimiter || '.'; | |
if (!keyChain) { throw Error('keyChain should not be a empty value')}; | |
var keys = keyChain.split(delimiter); | |
console.log(keys); | |
try { | |
for (var i = 0; i < keys.length; i++) { | |
obj = obj[keys[i]] | |
if (obj === undefined) { return null;}; |
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
(function($) { | |
var key = 'history:mock'; | |
var historyDb = { | |
cursor: null, | |
action: null, | |
urls: [] | |
}; | |
function saveState() { | |
sessionStorage.setItem(key, JSON.stringify(historyDb)); | |
} |
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
<?php | |
function msort(&$data, $field, $order='asc') { | |
return usort($data, function($a, $b) use ($field, $order) { | |
return $order==='asc' ? $a[$field] < $b[$field] : $a[$field] > $b[$field]; | |
}); | |
} | |
//example | |
$data = array(array('t'=>1, 'p'=>'aBc'), array('t'=>3, 'p'=>'aBb')); | |
$rzt = msort($data, 't', 'asc'); |
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
<?php | |
class SortHelper { | |
private static $field; | |
static function byField(&$data, $field) { | |
self::$field = $field; | |
return usort($data, array('self', 'cmp')); | |
} | |
private static function cmp($a, $b) { | |
return $a[self::$field] > $b[self::$field]; | |
} |
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
function testClosure(paramClosure) { | |
var innerClosure = 100; | |
return function() { | |
paramClosure++; | |
innerClosure--; | |
} | |
} |
OlderNewer