Skip to content

Instantly share code, notes, and snippets.

@zhanhongtao
Last active December 22, 2015 06:49
Show Gist options
  • Save zhanhongtao/6433729 to your computer and use it in GitHub Desktop.
Save zhanhongtao/6433729 to your computer and use it in GitHub Desktop.
匿名函数
// 自执行函数
;(function() {
//...
})();
// dom 绑定.
document.onclick = function () {
// ....
};
document.addEventListener( 'click', function() {
// ...
}, false );)
document.attachEvent( 'onclick', function() {
// ...
});
setTimeout(function() {
// ...
}, wait);
setInterval(function() {
// ...
}, wait);
// jQuery.promise
$.promise().done(function() {}).fail(function() {});
// 字符串替换 - replace
'?path=p2'.replace( /[\?|&]path=([^#&]*)/i, function( r0, r1, index, string ) {
// ...
});
// sort 排序
[1,2,3,2,1].sort(function( a, b ) {
// ...
});
// 函数执行返回函数.
function bind(func, context) {
return function() {
return func.apply( context || this, arguments );
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment