mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 23:41:41 +08:00
存量题库数据更新
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
<p>Write a function that checks if a given object is an instance of a given class or superclass.</p>
|
||||
<p>Write a function that checks if a given value is an instance of a given class or superclass. For this problem, an object is considered an instance of a given class if that object has access to that class's methods.</p>
|
||||
|
||||
<p>There are no constraints on the data types that can be passed to the function.</p>
|
||||
<p>There are no constraints on the data types that can be passed to the function. For example, the value or the class could be <code>undefined</code>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> func = () => checkIfInstance(new Date(), Date)
|
||||
<strong>Input:</strong> func = () => checkIfInstanceOf(new Date(), Date)
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation: </strong>The object returned by the Date constructor is, by definition, an instance of Date.
|
||||
</pre>
|
||||
@@ -14,19 +14,19 @@
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> func = () => { class Animal {}; class Dog extends Animal {}; return checkIfInstance(new Dog(), Animal); }
|
||||
<strong>Input:</strong> func = () => { class Animal {}; class Dog extends Animal {}; return checkIfInstanceOf(new Dog(), Animal); }
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong>
|
||||
class Animal {};
|
||||
class Dog extends Animal {};
|
||||
checkIfInstance(new Dog(), Animal); // true
|
||||
checkIfInstanceOf(new Dog(), Animal); // true
|
||||
|
||||
Dog is a subclass of Animal. Therefore, a Dog object is an instance of both Dog and Animal.</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> func = () => checkIfInstance(Date, Date)
|
||||
<strong>Input:</strong> func = () => checkIfInstanceOf(Date, Date)
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation: </strong>A date constructor cannot logically be an instance of itself.
|
||||
</pre>
|
||||
@@ -34,7 +34,7 @@ Dog is a subclass of Animal. Therefore, a Dog object is an instance of both Dog
|
||||
<p><strong class="example">Example 4:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> func = () => checkIfInstance(5, Number)
|
||||
<strong>Input:</strong> func = () => checkIfInstanceOf(5, Number)
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation: </strong>5 is a Number. Note that the "instanceof" keyword would return false.
|
||||
<strong>Explanation: </strong>5 is a Number. Note that the "instanceof" keyword would return false. However, it is still considered an instance of Number because it accesses the Number methods. For example "toFixed()".
|
||||
</pre>
|
||||
|
Reference in New Issue
Block a user