There is nothing wrong with obj displaying Object. Why it’s not executed? It’s because you didn’t call it. Look at the line of code you commented above, obj.sleep(), which is the calling code.
Second question: The defined obj variable only refers to the methods and properties of the Person object, so what is printed is the Object object and its properties and methods
Thanks for the invitation~
It is equivalent to registering an attribute for obj
named: sleep,
value: a declared function,
You need to call a function to execute it, as we have already said above.
That is
obj.sleep()
You have to call the relevant function before it will be executed.
There is nothing wrong with object being an object created by new
Try executing it directly on the console
obj.sleep();
There is nothing wrong with obj displaying Object.
Why it’s not executed? It’s because you didn’t call it. Look at the line of code you commented above, obj.sleep(), which is the calling code.
console.log(obj.sleep()) Why did you comment out this section? Just this section will do
First question:
Second question: The defined obj variable only refers to the methods and properties of the Person object, so what is printed is the Object object and its properties and methods