DOM Events with Javascript Question

Hi, this question regards the “DOM Events with Javascript” exercise in “Building Interactive Javascript Websites”.

let sharePhoto = function(event) {
  event.target.style.display = 'none'; 
  + event.timeStamp + ' ms.';
}

share.onclick = sharePhoto;

In the last line, why can sharePhoto be passed without an argument or parentheses?

Also, why can the last line (share.onclick = sharePhoto;) not be put within another function on its’ own i.e without anonymous functions such as…

let eventAssignment = button => {
  button.onclick = function() {
    sharePhoto(event);
  }
};

and not just

let eventAssigment = button => {
  button.onclick = sharePhoto;
};

Many thanks

James

We don’t see where this (text) is defined.

3 Likes

It wasn’t relevant to the question but I have removed it anyway. The question is in regards to a syntax question, not the contents of the function.

2 Likes

Copy that.

1 Like