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
import React from 'react'; | |
// use forwardRef polyfills, preparing for future upgrades to React 16 | |
import forwardRef from 'create-react-ref/lib/forwardRef'; | |
const withProps = (defaultProps = {}) => Base => { | |
class WithRef extends React.Component { | |
render() { | |
const { forwardRef, ...rest } = this.props; | |
const mergedProps = { ...defaultProps, ...rest }; |
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 list = [1, 1, 2, 3,3,3, 2, 1, 2, 1]; | |
function parseList(result, node) { | |
if (result.length) { | |
const parent = result[result.length - 1]; | |
if (parent.value < node) { | |
if (!parent.children) | |
parent.children = []; | |
parent.children = parseList(parent.children, node) | |
} else { |
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
const copyToClipboard = input => { | |
const el = document.createElement('textarea'); | |
el.value = input; | |
// Prevent keyboard from showing on mobile | |
el.setAttribute('readonly', ''); | |
el.style.contain = 'strict'; | |
el.style.position = 'absolute'; |
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 {any} obj The object to inspect. | |
* @returns {boolean} True if the argument appears to be a plain object. | |
*/ | |
export default function isPlainObject(obj) { | |
if (typeof obj !== 'object' || obj === null) return false | |
let proto = obj | |
while (Object.getPrototypeOf(proto) !== null) { | |
proto = Object.getPrototypeOf(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 getParams(url) { | |
var result = {}; | |
url = decodeURI(url); | |
if (typeof url == "string" && url.indexOf("?") != -1) { | |
var params = url.match(/\?.*/)[0].trim().replace(/^\?/, "").split("&"); | |
for (var i = 0; i < params.length; i++) { | |
var temp = params[i].split("="); | |
result[temp[0]] = temp[1]; | |
} | |
} |
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 |
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 testindex = 0; | |
var loadInProgress = false;//This is set to true when a page is still loading | |
/*********SETTINGS*********************/ | |
var webPage = require('webpage'); | |
var page = webPage.create(); | |
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36'; | |
page.settings.javascriptEnabled = true; | |
page.settings.loadImages = false;//Script is much faster with this field set to false | |
phantom.cookiesEnabled = true; |
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
/** | |
* 作者:Alexa | |
* 链接:https://www.zhihu.com/question/40207029/answer/159826450 | |
* 来源:知乎 | |
* 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 | |
*/ | |
var Music163 = {}; | |
Music163.Send = function (index, count) { | |
var bd = NEJ.P, | |
cg = NEJ.O, |
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 upperFirstChar(str) { | |
// replace的第二个参数可以为函数,第一个为匹配到的字符串,第二个为匹配在原字符串中的索引,第三个为原字符串 | |
return str.replace(/\w+/g, function(match, offset, string){ | |
return match[0].toUpperCase() + match.slice(1); | |
}); | |
} | |
console.log(upperFirstChar(" hello, world my World hehe")); |