一道this的題目

2021-09-17 21:51:41 字數 505 閱讀 9475

請問下面**中的this值指向的是全域性物件還是物件o?

function f () 

return c();

}var o = new f();

console.log(o.constructor.name); // object

這裡的this指向全域性物件,因為 c() call without new。

這裡用正常的方式呼叫的函式 c() ,所以this指向全域性物件。

那麼下面的**呢?

function f () 

return this;

}return new c();

}var o = new f();

console.log(o.constructor.name); // c

在這裡在 c() 的前面新增了 new ,這個函式就變成了乙個建構函式,this 是乙個由 c() 構造器建立的乙個例項,所以在這裡 this 指向了o

一道題目 intel

從序列中找四個四字子串形成十進位制數使之乘積最大 就是求四個最大的?我目前只想到如下辦法。這個題並不是關於複雜的演算法,其本意是要利用並行處理,但目前尚未考慮到 除了其中比較求最小值部分有希望用simd include int g teststring int main void int picke...

一道題目 移位

csdn上一道面試題 十進位制整數,計算對應的二進位制數包含多少個1,用位操作。int n 95625 int m 1 int num 0 for int i 0 i sizeof int 8 i cout num endl 讓1不斷移位去判斷與其對應位置是否為1 若是有符號整數 負數 原碼的補碼 ...

一道簡單的題目

這是校賽的一道題,當時覺得挺難,後來就覺得簡單,知道思路後就很好做了。題目是這樣子的 1008 植樹節b time limit 1 sec memory limit 128 mb submit 4 solved 4 submit status web board description 植樹節那天每...