Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript jQuery Basics (2014) Creating a Password Confirmation Form Perform: Part 1

Nicholas Woods
Nicholas Woods
6,260 Points

I'm not really sure what Andrew means by a 'named method' in this video.

Andrew specifically says "let's create a named method" and then creates a function, this is a term I have not heard used before. Could someone please clarify what he means - or point me to specific resources that help.

Samuel Webb
Samuel Webb
25,370 Points

At what point in the video does he say that?

1 Answer

Jose Soto
Jose Soto
23,407 Points

He actually says named function, which happens to be called 'passwordEvent'. A named function provides a way to call a method again throughout your code. In this example, Andrew started the password length validator with an anonymous function tied to an event. Here is a simple example of an anonymous function:

$('button #my_button').click(function(){
    console.log('Hello');
});

The only time that function will be called is when the button with id 'my_button' is clicked. This is different from a named function like this;

function sayHello(){
    console.log('Hello');
}

A named function can be called again throughout your code by invoking the function like so:

sayHello();

// OR

$('button #my_button').click(sayHello);

Hope that helps. Cheers!

Nicholas Woods
Nicholas Woods
6,260 Points

Thanks for the reply, I actually got that wrong, it was not a named event, but he refers to this: 'kind of redundant, we could actually create a named method.' @7:56min into the video. Is he talking about a named function that calls a method?

Jose Soto
Jose Soto
23,407 Points

I see what you mean. He did say "named method" and I can see how that would be confusing. The terms 'method' and 'function' can get interchanged in programming speak. However, there is a difference between the two. A function is a block of code that can accept inputs and return outputs. A method is a function that is inside of a class.

So a method is a function, but a function is not necessarily a method. Andrew may have been thinking that the function he was creating will soon be placed into a class. In that case, the function would become a method.

This is the naming convention:

Outside of a Class

  1. Variable
  2. Function

Inside of a Class

  1. Property
  2. Method
Nicholas Woods
Nicholas Woods
6,260 Points

Thanks Jose, that cleared it up.