-1

What kind of JavaScript is this Page.getProximityListCallback = function(obj) {; is this a function?

Surely it is but what is it with this syntax? Can someone explain?

Update: Thank you for your answers. Here is a follow up: Why then use function Page() {}? What is its purpose? Why not just call getProximityListCallback()?

4 Answers 4

1

It's an anonymous function which is then assigned to a variable.

http://helephant.com/2008/08/javascript-anonymous-functions/

Sign up to request clarification or add additional context in comments.

Comments

0

This is something you can think of like adding a method to the Page class. In run-time. Method then will be accessible via the Page.getProximityListCallback() call.

Check here (JavaScript tab) - http://jsbin.com/arocu/edit.

BTW: it's a nice service to have fun with JavaScript.

Comments

0

Functions are "first class" values in JavaScript, that is, you can have a constant of type "function" and assign it to a variable or object member, just like you do with numbers or strings. Compare

    var foo = "cow";

and

    var bar = function() { }

Conceptually there is no difference between these two lines.

Comments

0

You can have namespaces in your JavaScript code using objects like this:

var Page = {};
Page.getProximityListCallback = function (obj) {
    // ...
};

And remember that

function func(obj) {
    // ...
}

is the same thing as

var func = function (obj) {
    // ...
};

So in your example you are assigning an anonymous function to the Page object's getProximityListCallback member.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.