这里整理记录以下过去一段时间学习和收集的一些JavaScript高级技巧
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
/*************************************************************************************************** | |
* @param {Array} [arr] [the array to be iterated] | |
* | |
* @param {Function} [process] [the callback to process the element in array] | |
* (elm, idx, arr, resolve) | |
* @description [process(elm, idx, arr, resolve) { return true; // return true to terminate current loop }] | |
* | |
* @param {Object} [options] [the iteration configurations] | |
* {loopStart, loopEnd, travType} | |
* @description [loopStart inclusive the index, loopEnd exclusive the index] |
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 uTools = {}; | |
/************************************ | |
Compatible solution for native methods | |
************************************/ | |
! function () { | |
'use strict'; | |
if (typeof Object.create != 'function') { | |
Object.create = function () { | |
var Temp = function () {}; | |
return function (proto) { |
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() { | |
if (typeof Array.prototype.forEach != 'function') { | |
Array.prototype.forEach = function(fn) { | |
var arr = Object(this), | |
i = 0, | |
len = 0; | |
if (Object.prototype.toString.call(arr).slice(8, -1) != 'Array') { | |
console.log('Error: Array.prototype.indexOf - the caller must be an array!'); | |
return; | |
} |
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 _create = Object.create, | |
_slice = Array.prototype.slice, | |
_toString = Object.prototype.toString, | |
_hasOwn = Object.prototype.hasOwnProperty; | |
/** | |
* [getTypeOf Get the data type of some data] | |
* @param {any type} arg [the data to get type] | |
* @return { string } [the string to describe the data type] | |
* | |
* usage: |
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 isArray (arg) { | |
return Object.prototype.toString.call(arg).slice(8, -1) === 'Array'; | |
} | |
/** | |
* [chunk Array chunk iteration] | |
* @param { array } arr [array to iterate] | |
* @param {function} fn [function to process array] | |
* @param {integer } intv [iteration interval milliseconds] | |
* @param {function} success [function for async invocation when iteration complete] | |
* @param { object } ctx [context to invoke the function] |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
收集GitHub使用技巧
Shortcut | Description | Shortcut | Description |
---|---|---|---|
Site wide shortcuts | ———— | Commit list | ———— |
s | Focus search bar | y | Expand URL to its canonical form |
g n | Go to Notifications | Dashboards | ———— |
g d | Go to Dashboard | g i | Go to your issues |
? | Bring up this help dialog | g p | Go to your pull requests |
OlderNewer