V 站从去年年中就好像开放深色模式了,但是切换样式一直都需要手动去切换,个人感觉有点麻烦。最近入手了 12,发现 iOS 的根据日出日落时间自动切换浅色深色模式的功能很好用,但是电脑端(Windows平台)不使用额外的软件不能实现自动切换样式,所以萌生了基于日出日落时间来自动切换 V 站样式模式的想法。
//使用箭头函数定义函数
var foo = () => { console.log(this) };
var obj = { aa:foo };
foo(); //Window
obj.aa(); //Window
明显使用箭头函数的时候,this的指向是没有发生变化的。
3.构造函数
//使用function方法定义构造函数
function Person(name, age){
this.name = name;
this.age = age;
}
var lenhart = new Person(lenhart, 25);
console.log(lenhart); //{name: 'lenhart', age: 25}
//尝试使用箭头函数
var Person = (name, age) =>{
this.name = name;
this.age = age;
};
var lenhart = new Person('lenhart', 25); //Uncaught TypeError: Person is not a constructor
foo(); //123
function foo(){
console.log('123');
}
arrowFn(); //Uncaught TypeError: arrowFn is not a function
var arrowFn = () => {
console.log('456');
};