The Hard Parts of Servers & Node.js

Calling a Function Under the Hood

Will Sentance

Will Sentance

The Hard Parts of Servers & Node.js

Check out a free preview of the full The Hard Parts of Servers & Node.js course

The "Calling a Function Under the Hood" Lesson is part of the full, The Hard Parts of Servers & Node.js course featured in this preview video. Here's what you'd learn in this lesson:

Will analyzes Node's role in running a function, including auto-running the function at the right time and inserting arguments.


Transcript from the "Calling a Function Under the Hood" Lesson

>> Will Sentance: Let's now, before we come to thumbs, we'll come to thumbs in a second. I just wanna finish up, I want us to have the message come in, I want to have Sarah Rose's inbound message come in. Let's remind ourselves, two parts of calling a function. Executing its code, in this function is gonna come and it's going to be presumably automatically.

How do I execute code, Charlie? What symbols tell me to execute code?
>> Speaker 2: Parentheses.
>> Will Sentance: Parentheses, I don't see myself adding any parentheses on there to do on incoming. So who do you think is going to add the parentheses, Charlie?
>> Charlie: Node will.
>> Will Sentance: Node is. But what did I say there's another part to executing code, taking its code and running it, what's the other thing that goes into executing code?

Raise your hand if you know. Matt.
>> Matt: Saving data.
>> Will Sentance: It's almost the right answer [LAUGH] Mohammed. Well it's not far off, what is the other thing that goes into running a function? Running its code and honestly yeah sort of but be a bit more specific, saving what data?

>> Matt: Returning the-
>> Will Sentance: Not, quite. Virginia? The other thing that happens when I want to run a function is I have to do what's that?
>> Speaker 5: I'll insert the parameter. The argument.
>> Will Sentance: Insert arguments, insert data. Two things running a function, parens on the end to make it run its code, the other thing insert data.

You know what? I have a feeling that, wouldn't it be amazing, if Node not only took this code do all incomings code and autoran it with what, Charlie, how does it autorun it? By adding?
>> Speaker 6: Parantheses.
>> Will Sentance: Parentheses, but also, if it were there to help me out by auto inserting arguments.

The other thing that is needed to run a function and wouldn't it be damn fantastic if those arguments were the very data that came from Sarah Rose's Mac. Because then inside the auto running code, I'd have access to all the data I need to determine what to send back.

That's exactly what happens. Let's have a look. Two parts of calling a function, executing its code and inserting its inputs, its arguments. In multiply by two or three, the argument's three and we the developer inserted it. We wrote it, I see it. I wrote it, look, three. Node will not only autorun our function by inserting behind the scenes what Charlie?

>> Charlie: Parenthesis.
>> Will Sentance: Parenthesis, easy to say it for now, it's gonna be correct the whole time. At the exact right moment. What's the exact right moment? When the message comes in which could be tomorrow, it could be seven weeks from now. Does it for us, it puts the parens on the end.

It'll also automatically insert whatever the pertinent data is, the relevant data is as, why did you insert the word additional? But additional, man. No, as the input, ignore that word additional, as the argument, as the input to that function. I meant the word additional to be one of the ones down here.

Sometimes it will additionally, even as a second argument, a second input, insert a set of functions in an object. And that those functions when they're run inside the auto-run function. The second input will be a bunch of functions that we will access to that when they're run will give us access back to node which might allow us to add data to the message to send back to the user.

We're going to see it in action. That's exactly what Node does.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now