How’s it going, I'm a Adam, a Full-Stack Engineer, actively searching for work. I'm all about JavaScript. And Frontend but don't let that fool you - I've also got some serious Backend skills.
Location
City of Bath, UK 🇬🇧
Education
10 plus years* active enterprise development experience and a Fine art degree 🎨
I used an IIFE recently to make computed properties on an object literal.
Given the following code:
attachEvent({
click: "some-element",
});
Now imagine I want that 'some-element' to be conditional. In this circumstance for the framework I'm using I cannot do this in a traditional way, that method is part of a class.
So I do this.
attachEvent((() => {
cont day = this.day; // value is wed
return {
click: day === 'thurs' ? 'some-element' : 'another-element';
}
})());
The result is a button that only works on Thursdays. The object was built up and returned in place by the IIFE. It was an edge case but it's certainly one way of doing it.
Very terse code though and maybe not great for your team.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I used an IIFE recently to make computed properties on an object literal.
Given the following code:
attachEvent({
click: "some-element",
});
Now imagine I want that 'some-element' to be conditional. In this circumstance for the framework I'm using I cannot do this in a traditional way, that method is part of a class.
So I do this.
attachEvent((() => {
cont day = this.day; // value is wed
return {
click: day === 'thurs' ? 'some-element' : 'another-element';
}
})());
The result is a button that only works on Thursdays. The object was built up and returned in place by the IIFE. It was an edge case but it's certainly one way of doing it.
Very terse code though and maybe not great for your team.