this.props 传递的值是引用至上层的,如果直接更改,其实也是更改了上层的数据,需要避免,要不然会发生一些很奇怪的意外情况;
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 strict'; | |
function GeneratePassword(length) { | |
var str1='qwertyuioplkjhgfdsazxcvbnm'; | |
var str2='QWERTYUIOPLKJHGFDSAZXCVBNM'; | |
var str3='1234567890'; | |
var str4='!@#$%^&*.,'; | |
var str = [str1,str2,str3,str4].join('') | |
var res = ''; | |
for (var i=0; i < length; i++) { |
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' | |
export default React | |
export class BasicComponent extends React.Component { | |
componentWillUnmount() { | |
this.willUnmount && this.willUnmount() | |
this.__unmount = true | |
} | |
componentDidMount() { |
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 mitt(all) { | |
all = all || Object.create(null) | |
return { | |
on(type, cb){ | |
(all[type] || (all[type] = [])).push(cb); | |
}, | |
off(type, cb){ | |
if (all[type]) { | |
all[type].splice(all[type].indexOf(cb) >>> 0, 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
/* | |
* usage | |
* | |
* componentDidMount() { | |
* likefetch('www.example.com/api/', {method: 'post', body: JSON.stringify({data: 123})}, c => this.xhr = c) | |
* } | |
* componentWillUnmount() { | |
* this.xhr && this.xhr.abort() | |
* } | |
* |
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 piexif = require('piexif'); | |
/* usage: | |
downloadPictureWithEXIFandRename('https://images.unsplash.com/photo-1502120492606-fba13cc63721?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=289f912c1f9e61361e64ac022a2a6ccc&auto=format&fit=crop&w=668&q=80', 'hello!') | |
*/ | |
function downloadPictureWithEXIFandRename(pictureUrl, pictureName, callback) { | |
var xhr = new XMLHttpRequest(); | |
var a = document.createElement('a'); | |
xhr.responseType = "arraybuffer"; | |
xhr.open('GET', pictureUrl, 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
function swap(arr, i, j) { | |
[arr[i], arr[j]] = [arr[j], arr[i]] | |
} | |
function quickSort(arr, low, high) { | |
let i, last; | |
if (low < high) { | |
last = low; | |
for (i = low + 1; i <= high; i++) { |
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 p = require('polka')(); | |
const debounce = require('lodash/debounce'); | |
p.get('/', (req, res) => { | |
res.end('hello world') | |
}) | |
const maxConnections = 10*10000; | |
const todos = ['hello']; | |
const users = Object.create(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 getNewState(getState, isOriginal) { | |
const state = getState(); | |
return isOriginal ? state : object.assign({}, state); | |
} | |
function createThunkMiddleware(extraArgument, errorHandler) { | |
return ({ dispatch, getState }) => next => action => { | |
if (typeof action === 'function') { | |
const result = action(dispatch, (isOriginal) => getNewState(getState, isOriginal), extraArgument); | |
if (errorHandler && result.catch) result.catch(errorHandler); | |
return result; |
OlderNewer