Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
86 views
in Technique[技术] by (71.8m points)

Function and Object Javascript

I've been reading the book named "Object Oriented Javascript" by Stoyan Stefanov. I see this sentence:

function is actually an object that is built with 'Function' constructor function (with capital F).

The author demonstrates this with some nice examples. However, based on that statement, I got this question that can't be answer by myself. As 'Function' constructor is a function, so 'Function' function is an Object, then 'Function' object needs another constructor function to build it and that another constructor function is again an Object (because it's a function).

Well, I end up with this endless logic. Can someone help me point out the wrong point in my thinking?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

'Function' function is an Object, then 'Function' object needs another constructor function to build it

No. Function is a native, builtin object whose properties and behavior are defined in section 15.3 of the EcmaScript specification. It was not built by an js function.

Think of it like that: There is a function somewhere in the code of your EcmaScript environment that builds function objects - it is called whenever your script encounters a function expression or declaration. The global Function function is a wrapper for that function to make it accessible for scripts. All function objects which that function returns inherit from the Function.prototype object - it looks like they were constructed by Function. Also the Function.prototype.constructor property that all functions inherit is defined to point to Function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...