实习日志-2(javascript)
var a = {n:1};
a.x= a = {n:2}; //此x时的a地址发生改变
console.log(a.x);
//console.log中的a是{n:2},该对象无x属性,输出undefind
function aname(){
console.log(arguments);
}
var a =[1,2,3];
aname(...a);//1,2,3
//`...`表示去结构化
//算符的优先级
Only the top last level of an object property reference chain matters to the call-site. For instance:
function foo() {
console.log( this.a );
}
var obj2 = {
a: 42,
foo: foo
};
var obj1 = {
a: 2,
obj2: obj2
};
obj1.obj2.foo(); // 42
//call function;
const concatAll = (array,fn) => {
let results = []
for(const value of array)
results.push.apply(results, value);
return results;
}
concatAll可拆解多个数组中的数组,将他们合成为一个数组。
eg:
arr = [[1,2,3,4],[5,6,7,8],[999,000]];
concatAll(arr);//[1, 2, 3, 4, 5, 6, 7, 8, 999, 0]
小工具:代码实现库(可查询一些方法的实现原理)
underscore.js
lodash.js
——2017.7.18实习于
http://map.baidu.com/?newmap=1&s=con%26wd%3D%E6%9D%8F%E6%9E%97%E6%B9%BE%E8%90%A5%E8%BF%90%E4%B8%AD%E5%BF%83%26c%3D194&from=alamap&tpl=mapdots