Understanding of key/function pairs in meteor.js

230
March 08, 2018, at 6:18 PM

I am not sure if my question is right here, but let's see. This piece of code ist taken from the meteor.js documentation:

Template.body.events({
  'submit .new-task'(event) {
    // Prevent default browser form submit
    event.preventDefault();
    // Get value from form element
    const target = event.target;
    const text = target.text.value;
    // Insert a task into the collection
    Tasks.insert({
      text,
      createdAt: new Date(), // current time
    });
    // Clear form
    target.text.value = '';
  },
});

(i.e. from here: https://www.meteor.com/tutorials/blaze/forms-and-events)

As far as i understand the code in Template.body.events({...code...}) is a dictionary. It seems to represent a key/function pair of the form:

KEY: 'submit .new-task'

FUNCTION: (event){...}

I have two questions here:

  1. why does it not contain a colon between the key and the function?
  2. is my understanding correct, that "(event){...code}" represents a function which will be executed immediately when KEY is accessed?

Thanks for your answer in advance!

Rent Charter Buses Company
READ ALSO
Highcharts return undefined value at a lot of data

Highcharts return undefined value at a lot of data

I write code to return value in chartI get data from cryptocompare

233
If else inside a function - calling the function in JavaScript

If else inside a function - calling the function in JavaScript

I'm trying to call the function that I've created, where the number is taken from a user input, unfortunately it does not workThis method is the same I've used in other function I've created and it work

174
jquery SSN format without masking?

jquery SSN format without masking?

I have input field for entering SSN

319