Skip to content

Instantly share code, notes, and snippets.

View vino24's full-sized avatar
🎯
Focusing

逢十借一 vino24

🎯
Focusing
View GitHub Profile
@vino24
vino24 / strategyPattern.js
Created June 4, 2017 09:15
策略模式实现表单验证
// 策略对象
const strategies = {
isNonEmpty(value, errorMsg) {
return value === '' ?
errorMsg : void 0
},
minLength(value, length, errorMsg) {
return value.length < length ?
errorMsg : void 0
},
@vino24
vino24 / arrayLikeConvert.js
Last active June 1, 2017 15:56
类数组转数组
const arrLike = {
length: 4,
2: "foo"
};
Array.from(arrLike); // [undefined, undefined, "foo", undefined] , length 是类数组对象必须的属性
// Array.from还可以接受一个映射函数作为第二个参数类似Array.map(..)
var arrLike = {
length: 4,
2: "foo"