-1

I came upon a notation I'm not too familiar with and would like some direction to where to look.

the notation is "selector event" : function() {}

so for example

".elementClass change" : function() {}

6
  • 4
    It's just a key pointing to a function. It's not special. Is this in Backbone? Commented Apr 5, 2013 at 5:20
  • 1
    What libraries are you using? Commented Apr 5, 2013 at 5:20
  • Backbone.js uses something like this: backbonejs.org/#View-delegateEvents Commented Apr 5, 2013 at 5:22
  • It could be a simple conditional condition ? true_expr : false_expr syntax that gives you string if true, and an empty function otherwise. Commented Apr 5, 2013 at 5:23
  • Looks like Backbone.js to me, except that backbone syntax is "event selector": function(){} Commented Apr 5, 2013 at 5:23

1 Answer 1

1

This notation is for a key-value pair within an object. The specific example is for a function value belonging to a selector and event key. The function is then accessible using the key:

var obj = {
    ".elementClass change": function () {}
};
var func = obj[".elementClass change"];
Sign up to request clarification or add additional context in comments.

2 Comments

Found the notation in javascriptmvc. Thanks for the explanation on key-value pairs in javascript. I'm sure jmvc is using it for the event listeners.
@WillHuang Yup it parses the key finds the elements that match the selector and attach event listeners for the event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.