自定义原型方法、去重、封装typeof(十七)

2020/6/24 JS

# 面试题

# 题目1

/**
 * GO = {
 * test1: undefined -> new Test()
 * test2: undefined -> new Test()
 * Test: function Test() {...}
 * }
 * 
 * AO = {
 *  d: undefined -> 0
 *  e: function e() {...}
 * }
 */
function Test(a, b, c) {
  var d = 0;
  this.a = a;
  this.b = b;
  this.c = c;

  function e() {
    d++;
    console.log(d);
  }

  this.f = e;
}

var test1 = new Test();

test1.f(); // 1
test1.f(); // 2
var test2 = new Test();
test2.f(); // 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

# 题目2

function test() {
  console.log(typeof(arguments)); // 'object'
}

test();

var test = function a() {
  console.log(test.name); // 'a'
  return 'a';
}

test();

console.log(typeof(a)); // 'undefined'
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 题目3

function test(day) {
 var weekday = [
   'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'
 ];

 weekday[day - 1] !== undefined ? console.log(weekday[day - 1])
                                : console.log('I don\'t know');
}

test(7); // 'Sun'

var arr = [,1,2,,,3,4];
console.log(arr[0]); // undefined
1
2
3
4
5
6
7
8
9
10
11
12
13
Last Updated: 2022/7/21 10:52:53
Genshin Impact bgm
Genshin Impact