javascript - console.log prints variables of a new object
高洛峰
高洛峰 2017-07-05 11:02:39
0
6
1035

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(6)
为情所困

Thanks for the invitation~

obj.sleep = function(){console.log("sleep")}

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()

typecho

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

ringa_lee

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template