vue's People
vue's Issues
略读源码
Object.create(null); 创建空 json
正则 replace
//function(匹配到的元素,替换后的元素,被匹配到的index,str)
str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; })
Object.keys(a) 要返回其枚举自身属性的对象
Object.values()和Object.keys()是相反的操作,把一个对象的值转换为数组
// 一、处理对象,返回可枚举的属性数组
let person2 = {name:"张三",age:25,address:"深圳",getName:function(){}}
console.log(Object.keys(person2)); // ["name", "age", "address", "getName"]
//常用技巧
Object.keys(person2).map( (key)=>{ return person[key] } ) //["张三", 25, "深圳", ƒ]
//二、处理数组,返回索引值
let arr1 = ['a', 'b', 'c'];
console.log(Object.keys(arr1)); // ["0", "1", "2"]
//三、处理字符串,返回索引值数组
let str1 = '123abc字符串';
console.log(Object.keys(str1)); //["0", "1", "2", "3", "4", "5", "6", "7", "8"]
Array.every
var aa = [{"111":"aa"},{"222":"bbbb"}];
aa.every(function(match, index, aaArray){console.log(match);console.log(index);console.log(aaArray);})
bind实现
/* istanbul ignore next */
function polyfillBind (fn, ctx) {
function boundFn (a) {
var l = arguments.length;
return l
? l > 1
? fn.apply(ctx, arguments)
: fn.call(ctx, a)
: fn.call(ctx)
}
boundFn._length = fn.length;
return boundFn
}
function nativeBind (fn, ctx) {
return fn.bind(ctx)
}
var bind = Function.prototype.bind
? nativeBind
: polyfillBind;
reduce() 方法接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值。
reduce() 可以作为一个高阶函数,用于函数的 compose。
注意: reduce() 对于空数组是不会执行回调函数的。
array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
绑定一次事件
function once (fn) {
var called = false;
return function () {
if (!called) {
called = true;
fn.apply(this, arguments);
}
}
}
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.