最近为公司面试了一些中高级的前端开发中,主要简单考察了下原型,异步和this指向,如下是自己亲出的一小套测试题!
一:有一个类如下
function Person(name) {
this.name = name
}
let p = new Person(‘Tom’);
1: p.__proto__等于什么?
2: Person.__proto__等于什么?
二:请写出下面console的值
var foo = {},
F = function({};
Object.prototype.a = ‘value a’;
Function.prototype.b = ‘value b’;
console.log(foo.a)
console.log(foo.b)
console.log(F.a)
console.log(F.b)
三:如下console的值是?
function Person (name) {
this.name = name;
}
function Student () {}
Student.prototype = Person.prototype;
Student.prototype.constructor = Student;
let s = new Student(‘Tom’);
console.log(s instanceof Person);
四:下面代码输出什么?
for(var i = 0; i < 10; i++) {
setTimeout(() => {
console.log(i)
}, 0)
}
五:下面的结果是什么
console.log(‘a’);
setTimeout(() => {
console.log(‘b’);
}, 0);
console.log(‘c’);
Promise.resolve().then(() => {
console.log(‘d’);
}).then(() => {
console.log(‘e’);
});
console.log(‘f’);
六:如下console的值是?
var User = {
count: 1,
getCount: function() {
return this.count;
}
};
console.log(User.getCount()); // what?
var func = User.getCount;
console.log(func()); // what?
七:回答以下代码,alert的值分别是多少?
var a = 100;
function test(){
alert(a);
a = 10;
alert(a);
}
test();
alert(a);