I primarily write code in C#. However, I'm working with some JavaScript. I have defined a class in JavaScript as shown here:
function Item(id, name) {
this.ID = id;
this.Name = name;
// define event submitCompleted
this.submit = function() {
// When the submission is completed, fire "submitCompleted" event.
};
}
My challenge is, I don't know how to create and fire custom events in JavaScript. If this was C#, I'd do the following:
public class Item
{
public string ID { get; set; }
public string Name { get; set; }
public Item(string id, string name)
{
this.ID = id;
this.Name = name;
}
public event EventHandler SubmitCompleted;
public void Submit()
{
// Submission logic
SubmitCompleted(this, EventArgs.Empty);
}
}
How do I do the equivalent in JavaScript? Thank you!