0 votes
by (260 points)

I'm relearning JavaScript and it's difficult to pick up its sometimes really strange syntax and conventions.

I have a jQuery event which adds tag information to "#main .passage". It looks sort of like this:

$(".passage").on('show.sm.passage', function(event) {
	var tags = ??? // something here
	$(".passage").attr("data-tags", tags.join(" "));
});

The event triggers fine, but I don't understand something in the source code (which will, according to the comment, allow me to access some basic information about the passage being displayed).

/**
 Triggered whenever a passage is about to be shown onscreen. The passage
 being displayed is stored in the passage property of the event.
 @event showpassage
**/

this.$passageEl.trigger('show.sm.passage', { passage: passage });

What do I do with the object? How can I access that within the event?

I tried

event.passage;

but all I get is undefined. Anyone have experience with this?

I'm not using 1.3 Snowman, it's the newer 2.0.0 from the github source. There doesn't seem to be any significant difference between the two besides some compatibility fixes.

1 Answer

0 votes
by (260 points)
 
Best answer

I got the answer! The passage is a separate argument to the function.

$(".passage").on('show.sm.passage', function(event, eventArgs) {
	var tags = eventArgs.passage.tags;
	$(".passage").attr("data-tags", tags.join(" "));
});

 

...