函数柯里化
是把接收多个参数的函数变换成接收一个单一参数(最初函数的第一个参数)的函数,并返回接受剩余的参数而且返回结果的新函数的技术。
function add(x) {
return function (y) {
console.log(x + y);
}
}
add(1)(2); //3
class类
class Person { //定义了一个名字为Person的类
constructor(name, age) { //constructor是一个构造方法,用来接收参数
this.name = name; //this代表的是实例对象
this.age = age;
}
say() {
//这是一个类的方法,注意千万不要加上function
return "我的名字叫" + this.name + "今年" + this.age + "岁了";
}
}
const obj = new Person("maomin", 22);
console.log(obj.say()); //我的名字叫maomin今年22岁了
微信公众号:前端历劫之路,欢迎关注。