Javascript pattern help needed

This is actually from a typescript file, but can someone explain this pattern to me:
public filter(filter?: (index: number) => boolean): void {
	this._filter = filter;
	if (this._data) {
	    this.buildLocalData();
	}
}

Open in new window

So the name of function becomes a function param ('filter?'), and also is a class within the function ('=filter;')?
I'm trying to get my head round that.
Silas2Asked:
Who is Participating?
 
Steve BinkCommented:
It means that the first parameter is optional (?), and should be a function which itself takes a single numeric parameter and returns a boolean.  

http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.