基本结构:箭头函数左边是参数,右边是返回值
//创建func函数
let func = num => num;
//上面的func函数等价于
let oldFunc = function (num) {
return num
};//如果存在多个参数,参数需要括号包起来
let sum = (num1, num2) => num1 + num2;
//上面的sum函数等价于
let oldSum = function (num1, num2) {
return num1 + num2;
};//如果返回值需要大量逻辑,并且一个表达式写不完,需要用花括号包起来返回体
let chkUsername = username => {
if (username == 'zhang') {
return 1;
} else if (username == 'li') {
return 2;
} else {
return 3;
}
}//箭头函数的返回值支持使用已定义的函数
let getInt = num => parseInt(num);
//箭头函数的this,这是以前this的作用域,在函数中创建闭包,此时的this变了
let userAge = {
age: 1,
getAge: function () {
var fn = function () {
return this.age //此时的this指向的是windows
}
return fn();
},
setAge: function (age) {
this.age = age;
}
};
userAge.setAge(19);
console.log(userAge.getAge())//箭头函数this总是指向词法作用域,也就是外层调用者obj
let userNewAge = {
age: 1,
getAge: function () {
let fn = ()=>(this.age)
return fn();
},
setAge: function (age) {
this.age = age;
}
};
userNewAge.setAge(19);
console.log(userNewAge.getAge()) 离线缓存的开启实例使用apache设置 1.apache配置文件搜索Addtype,我的addtype已经存在项目,如下 AddType application/x-compress .Z AddType application/x-gz...
捕捉模式从DOM最顶层一直到最后一层,冒泡正好相反,具体运行以下实例测试.<!DOCTYPE html> <html> <head> <title>捕捉和冒泡</title> <meta charset="...
https://3gimg.qq.com/lightmap/v1/marker/index.html?marker=coord:37.6767600000,112.7297800000&key=TKUBZ-D24AF-GJ4JY-JDVM2-IBYKK-KEBCU&referer=p...
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script type...
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无标题文档</title> </head> ...
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>获取mac地址</title> </head&g...