How to simplify multiple functions that have different ids
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to simplify the following code:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
document.getElementById("newFloorplan").addEventListener("click", function (event)
filesystem.newFloorplan();
event.preventDefault();
);
document.getElementById("showOpenWindow").addEventListener("click", function (event)
filesystem.showOpenWindow();
event.preventDefault();
);
document.getElementById("saveFloorplan").addEventListener("click", function (event)
filesystem.saveFloorplan();
event.preventDefault();
);
document.getElementById("saveFloorplanAs").addEventListener("click", function (event)
filesystem.saveFloorplanAs();
event.preventDefault();
);
document.getElementById("showRemoveWindow").addEventListener("click", function (event)
filesystem.showRemoveWindow();
event.preventDefault();
);
It's starting to take up a lot of room and look messy.
javascript
add a comment |
I am trying to simplify the following code:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
document.getElementById("newFloorplan").addEventListener("click", function (event)
filesystem.newFloorplan();
event.preventDefault();
);
document.getElementById("showOpenWindow").addEventListener("click", function (event)
filesystem.showOpenWindow();
event.preventDefault();
);
document.getElementById("saveFloorplan").addEventListener("click", function (event)
filesystem.saveFloorplan();
event.preventDefault();
);
document.getElementById("saveFloorplanAs").addEventListener("click", function (event)
filesystem.saveFloorplanAs();
event.preventDefault();
);
document.getElementById("showRemoveWindow").addEventListener("click", function (event)
filesystem.showRemoveWindow();
event.preventDefault();
);
It's starting to take up a lot of room and look messy.
javascript
add a comment |
I am trying to simplify the following code:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
document.getElementById("newFloorplan").addEventListener("click", function (event)
filesystem.newFloorplan();
event.preventDefault();
);
document.getElementById("showOpenWindow").addEventListener("click", function (event)
filesystem.showOpenWindow();
event.preventDefault();
);
document.getElementById("saveFloorplan").addEventListener("click", function (event)
filesystem.saveFloorplan();
event.preventDefault();
);
document.getElementById("saveFloorplanAs").addEventListener("click", function (event)
filesystem.saveFloorplanAs();
event.preventDefault();
);
document.getElementById("showRemoveWindow").addEventListener("click", function (event)
filesystem.showRemoveWindow();
event.preventDefault();
);
It's starting to take up a lot of room and look messy.
javascript
I am trying to simplify the following code:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
document.getElementById("newFloorplan").addEventListener("click", function (event)
filesystem.newFloorplan();
event.preventDefault();
);
document.getElementById("showOpenWindow").addEventListener("click", function (event)
filesystem.showOpenWindow();
event.preventDefault();
);
document.getElementById("saveFloorplan").addEventListener("click", function (event)
filesystem.saveFloorplan();
event.preventDefault();
);
document.getElementById("saveFloorplanAs").addEventListener("click", function (event)
filesystem.saveFloorplanAs();
event.preventDefault();
);
document.getElementById("showRemoveWindow").addEventListener("click", function (event)
filesystem.showRemoveWindow();
event.preventDefault();
);
It's starting to take up a lot of room and look messy.
javascript
javascript
asked Nov 15 '18 at 14:50
Jon NowakJon Nowak
54110
54110
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
Simply call wrapper function with dynamic values for ID and function name:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
function bindEvent(id, callbackFunction)
document.getElementById(id).addEventListener('click', function (event))
event.preventDefault();
filesystem[callbackFunction]();
bindEvent('newFloorplan', 'newFloorplan');
bindEvent('showOpenWindow', 'showOpenWindow');
...
I would prefer to use in bindEvent callback, not function name: use: callbackFunction(); and then: bindEvent('newFloorplan', filesystem.newFloorplan); In this way bindEvent will be more generic :).
– Grzesiek Danowski
Nov 15 '18 at 15:03
@GrzesiekDanowski you'd need to usefilesystem.newFloorplan.bind(filesystem)
to make that work properly.
– Alnitak
Nov 15 '18 at 15:10
Awesome, Thank You-
– Jon Nowak
Nov 15 '18 at 15:35
Can I use this method for something like this: 'var ui = new fp.FloorplanUI(myFloorplan, "ui", "myFloorplan", fp.GUI_STATE); function bindEvent(id, floorplanUIFunction, div) document.getElementById(id).addEventListener('click', function (event) event.preventDefault(); ui[floorplanUIFunction]([div]); ); bindEvent('diagramHelpDivButton', 'hideShow', 'diagramHelpDiv');'
– Jon Nowak
Nov 15 '18 at 15:35
add a comment |
You can access the property of an object by a variable containing a string using bracket notation.
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
var el = document.getElementById(id);
el.addEventListener('click', function(event)
filesystem[id]();
event.preventDefault();
);
);
add a comment |
const filesystem = new fp.FloorplanFilesystem (myFloorplan, fp.FILESYSTEM_UI_STATE)
const ids = ['newFloorplan', 'showOpenWindow', 'saveFloorplan', 'saveFloorplanAs', 'showRemoveWindow']
const handler = id => event => (filesystem [id] (), event.preventDefault ())
ids.forEach (id => document.getElementById (id).addEventListener ('click', handler (id)))
add a comment |
Since your elements use the name of the function that you want to invoke as their ID, you can extract that within the event handler:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
function fs_handler(event)
filesystem[event.target.id]();
event.preventDefault();
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
document.getElementById(id).addEventHandler('click', fs_handler);
);
This should be generally preferred over creating a new callback function object for each item.
Furthermore, if the clickable elements all share a common parent, you could just register the event handler on that, via event delegation, saving the need to register each button individually.
add a comment |
My proposition (es6) - "code from head":
[
"newFloorplan",
"showOpenWindow",
"saveFloorplan",
"saveFloorplanAs",
"showRemoveWindow",
].map(id=>document.getElementById(id).addEventListener('click', event=>
filesystem[id]();
event.preventDefault()
));
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322064%2fhow-to-simplify-multiple-functions-that-have-different-ids%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Simply call wrapper function with dynamic values for ID and function name:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
function bindEvent(id, callbackFunction)
document.getElementById(id).addEventListener('click', function (event))
event.preventDefault();
filesystem[callbackFunction]();
bindEvent('newFloorplan', 'newFloorplan');
bindEvent('showOpenWindow', 'showOpenWindow');
...
I would prefer to use in bindEvent callback, not function name: use: callbackFunction(); and then: bindEvent('newFloorplan', filesystem.newFloorplan); In this way bindEvent will be more generic :).
– Grzesiek Danowski
Nov 15 '18 at 15:03
@GrzesiekDanowski you'd need to usefilesystem.newFloorplan.bind(filesystem)
to make that work properly.
– Alnitak
Nov 15 '18 at 15:10
Awesome, Thank You-
– Jon Nowak
Nov 15 '18 at 15:35
Can I use this method for something like this: 'var ui = new fp.FloorplanUI(myFloorplan, "ui", "myFloorplan", fp.GUI_STATE); function bindEvent(id, floorplanUIFunction, div) document.getElementById(id).addEventListener('click', function (event) event.preventDefault(); ui[floorplanUIFunction]([div]); ); bindEvent('diagramHelpDivButton', 'hideShow', 'diagramHelpDiv');'
– Jon Nowak
Nov 15 '18 at 15:35
add a comment |
Simply call wrapper function with dynamic values for ID and function name:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
function bindEvent(id, callbackFunction)
document.getElementById(id).addEventListener('click', function (event))
event.preventDefault();
filesystem[callbackFunction]();
bindEvent('newFloorplan', 'newFloorplan');
bindEvent('showOpenWindow', 'showOpenWindow');
...
I would prefer to use in bindEvent callback, not function name: use: callbackFunction(); and then: bindEvent('newFloorplan', filesystem.newFloorplan); In this way bindEvent will be more generic :).
– Grzesiek Danowski
Nov 15 '18 at 15:03
@GrzesiekDanowski you'd need to usefilesystem.newFloorplan.bind(filesystem)
to make that work properly.
– Alnitak
Nov 15 '18 at 15:10
Awesome, Thank You-
– Jon Nowak
Nov 15 '18 at 15:35
Can I use this method for something like this: 'var ui = new fp.FloorplanUI(myFloorplan, "ui", "myFloorplan", fp.GUI_STATE); function bindEvent(id, floorplanUIFunction, div) document.getElementById(id).addEventListener('click', function (event) event.preventDefault(); ui[floorplanUIFunction]([div]); ); bindEvent('diagramHelpDivButton', 'hideShow', 'diagramHelpDiv');'
– Jon Nowak
Nov 15 '18 at 15:35
add a comment |
Simply call wrapper function with dynamic values for ID and function name:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
function bindEvent(id, callbackFunction)
document.getElementById(id).addEventListener('click', function (event))
event.preventDefault();
filesystem[callbackFunction]();
bindEvent('newFloorplan', 'newFloorplan');
bindEvent('showOpenWindow', 'showOpenWindow');
...
Simply call wrapper function with dynamic values for ID and function name:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
function bindEvent(id, callbackFunction)
document.getElementById(id).addEventListener('click', function (event))
event.preventDefault();
filesystem[callbackFunction]();
bindEvent('newFloorplan', 'newFloorplan');
bindEvent('showOpenWindow', 'showOpenWindow');
...
answered Nov 15 '18 at 14:56
JustinasJustinas
27.7k33763
27.7k33763
I would prefer to use in bindEvent callback, not function name: use: callbackFunction(); and then: bindEvent('newFloorplan', filesystem.newFloorplan); In this way bindEvent will be more generic :).
– Grzesiek Danowski
Nov 15 '18 at 15:03
@GrzesiekDanowski you'd need to usefilesystem.newFloorplan.bind(filesystem)
to make that work properly.
– Alnitak
Nov 15 '18 at 15:10
Awesome, Thank You-
– Jon Nowak
Nov 15 '18 at 15:35
Can I use this method for something like this: 'var ui = new fp.FloorplanUI(myFloorplan, "ui", "myFloorplan", fp.GUI_STATE); function bindEvent(id, floorplanUIFunction, div) document.getElementById(id).addEventListener('click', function (event) event.preventDefault(); ui[floorplanUIFunction]([div]); ); bindEvent('diagramHelpDivButton', 'hideShow', 'diagramHelpDiv');'
– Jon Nowak
Nov 15 '18 at 15:35
add a comment |
I would prefer to use in bindEvent callback, not function name: use: callbackFunction(); and then: bindEvent('newFloorplan', filesystem.newFloorplan); In this way bindEvent will be more generic :).
– Grzesiek Danowski
Nov 15 '18 at 15:03
@GrzesiekDanowski you'd need to usefilesystem.newFloorplan.bind(filesystem)
to make that work properly.
– Alnitak
Nov 15 '18 at 15:10
Awesome, Thank You-
– Jon Nowak
Nov 15 '18 at 15:35
Can I use this method for something like this: 'var ui = new fp.FloorplanUI(myFloorplan, "ui", "myFloorplan", fp.GUI_STATE); function bindEvent(id, floorplanUIFunction, div) document.getElementById(id).addEventListener('click', function (event) event.preventDefault(); ui[floorplanUIFunction]([div]); ); bindEvent('diagramHelpDivButton', 'hideShow', 'diagramHelpDiv');'
– Jon Nowak
Nov 15 '18 at 15:35
I would prefer to use in bindEvent callback, not function name: use: callbackFunction(); and then: bindEvent('newFloorplan', filesystem.newFloorplan); In this way bindEvent will be more generic :).
– Grzesiek Danowski
Nov 15 '18 at 15:03
I would prefer to use in bindEvent callback, not function name: use: callbackFunction(); and then: bindEvent('newFloorplan', filesystem.newFloorplan); In this way bindEvent will be more generic :).
– Grzesiek Danowski
Nov 15 '18 at 15:03
@GrzesiekDanowski you'd need to use
filesystem.newFloorplan.bind(filesystem)
to make that work properly.– Alnitak
Nov 15 '18 at 15:10
@GrzesiekDanowski you'd need to use
filesystem.newFloorplan.bind(filesystem)
to make that work properly.– Alnitak
Nov 15 '18 at 15:10
Awesome, Thank You-
– Jon Nowak
Nov 15 '18 at 15:35
Awesome, Thank You-
– Jon Nowak
Nov 15 '18 at 15:35
Can I use this method for something like this: 'var ui = new fp.FloorplanUI(myFloorplan, "ui", "myFloorplan", fp.GUI_STATE); function bindEvent(id, floorplanUIFunction, div) document.getElementById(id).addEventListener('click', function (event) event.preventDefault(); ui[floorplanUIFunction]([div]); ); bindEvent('diagramHelpDivButton', 'hideShow', 'diagramHelpDiv');'
– Jon Nowak
Nov 15 '18 at 15:35
Can I use this method for something like this: 'var ui = new fp.FloorplanUI(myFloorplan, "ui", "myFloorplan", fp.GUI_STATE); function bindEvent(id, floorplanUIFunction, div) document.getElementById(id).addEventListener('click', function (event) event.preventDefault(); ui[floorplanUIFunction]([div]); ); bindEvent('diagramHelpDivButton', 'hideShow', 'diagramHelpDiv');'
– Jon Nowak
Nov 15 '18 at 15:35
add a comment |
You can access the property of an object by a variable containing a string using bracket notation.
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
var el = document.getElementById(id);
el.addEventListener('click', function(event)
filesystem[id]();
event.preventDefault();
);
);
add a comment |
You can access the property of an object by a variable containing a string using bracket notation.
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
var el = document.getElementById(id);
el.addEventListener('click', function(event)
filesystem[id]();
event.preventDefault();
);
);
add a comment |
You can access the property of an object by a variable containing a string using bracket notation.
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
var el = document.getElementById(id);
el.addEventListener('click', function(event)
filesystem[id]();
event.preventDefault();
);
);
You can access the property of an object by a variable containing a string using bracket notation.
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
var el = document.getElementById(id);
el.addEventListener('click', function(event)
filesystem[id]();
event.preventDefault();
);
);
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
var el = document.getElementById(id);
el.addEventListener('click', function(event)
filesystem[id]();
event.preventDefault();
);
);
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
var el = document.getElementById(id);
el.addEventListener('click', function(event)
filesystem[id]();
event.preventDefault();
);
);
answered Nov 15 '18 at 14:58
dgearedgeare
2,05731423
2,05731423
add a comment |
add a comment |
const filesystem = new fp.FloorplanFilesystem (myFloorplan, fp.FILESYSTEM_UI_STATE)
const ids = ['newFloorplan', 'showOpenWindow', 'saveFloorplan', 'saveFloorplanAs', 'showRemoveWindow']
const handler = id => event => (filesystem [id] (), event.preventDefault ())
ids.forEach (id => document.getElementById (id).addEventListener ('click', handler (id)))
add a comment |
const filesystem = new fp.FloorplanFilesystem (myFloorplan, fp.FILESYSTEM_UI_STATE)
const ids = ['newFloorplan', 'showOpenWindow', 'saveFloorplan', 'saveFloorplanAs', 'showRemoveWindow']
const handler = id => event => (filesystem [id] (), event.preventDefault ())
ids.forEach (id => document.getElementById (id).addEventListener ('click', handler (id)))
add a comment |
const filesystem = new fp.FloorplanFilesystem (myFloorplan, fp.FILESYSTEM_UI_STATE)
const ids = ['newFloorplan', 'showOpenWindow', 'saveFloorplan', 'saveFloorplanAs', 'showRemoveWindow']
const handler = id => event => (filesystem [id] (), event.preventDefault ())
ids.forEach (id => document.getElementById (id).addEventListener ('click', handler (id)))
const filesystem = new fp.FloorplanFilesystem (myFloorplan, fp.FILESYSTEM_UI_STATE)
const ids = ['newFloorplan', 'showOpenWindow', 'saveFloorplan', 'saveFloorplanAs', 'showRemoveWindow']
const handler = id => event => (filesystem [id] (), event.preventDefault ())
ids.forEach (id => document.getElementById (id).addEventListener ('click', handler (id)))
answered Nov 15 '18 at 15:02
leninelleninel
17914
17914
add a comment |
add a comment |
Since your elements use the name of the function that you want to invoke as their ID, you can extract that within the event handler:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
function fs_handler(event)
filesystem[event.target.id]();
event.preventDefault();
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
document.getElementById(id).addEventHandler('click', fs_handler);
);
This should be generally preferred over creating a new callback function object for each item.
Furthermore, if the clickable elements all share a common parent, you could just register the event handler on that, via event delegation, saving the need to register each button individually.
add a comment |
Since your elements use the name of the function that you want to invoke as their ID, you can extract that within the event handler:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
function fs_handler(event)
filesystem[event.target.id]();
event.preventDefault();
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
document.getElementById(id).addEventHandler('click', fs_handler);
);
This should be generally preferred over creating a new callback function object for each item.
Furthermore, if the clickable elements all share a common parent, you could just register the event handler on that, via event delegation, saving the need to register each button individually.
add a comment |
Since your elements use the name of the function that you want to invoke as their ID, you can extract that within the event handler:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
function fs_handler(event)
filesystem[event.target.id]();
event.preventDefault();
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
document.getElementById(id).addEventHandler('click', fs_handler);
);
This should be generally preferred over creating a new callback function object for each item.
Furthermore, if the clickable elements all share a common parent, you could just register the event handler on that, via event delegation, saving the need to register each button individually.
Since your elements use the name of the function that you want to invoke as their ID, you can extract that within the event handler:
var filesystem = new fp.FloorplanFilesystem(myFloorplan, fp.FILESYSTEM_UI_STATE);
function fs_handler(event)
filesystem[event.target.id]();
event.preventDefault();
["newFloorplan", "showOpenWindow", "saveFloorplan", "saveFloorplanAs", "showRemoveWindow"].forEach(function(id)
document.getElementById(id).addEventHandler('click', fs_handler);
);
This should be generally preferred over creating a new callback function object for each item.
Furthermore, if the clickable elements all share a common parent, you could just register the event handler on that, via event delegation, saving the need to register each button individually.
edited Nov 15 '18 at 15:22
answered Nov 15 '18 at 15:03
AlnitakAlnitak
275k62348437
275k62348437
add a comment |
add a comment |
My proposition (es6) - "code from head":
[
"newFloorplan",
"showOpenWindow",
"saveFloorplan",
"saveFloorplanAs",
"showRemoveWindow",
].map(id=>document.getElementById(id).addEventListener('click', event=>
filesystem[id]();
event.preventDefault()
));
add a comment |
My proposition (es6) - "code from head":
[
"newFloorplan",
"showOpenWindow",
"saveFloorplan",
"saveFloorplanAs",
"showRemoveWindow",
].map(id=>document.getElementById(id).addEventListener('click', event=>
filesystem[id]();
event.preventDefault()
));
add a comment |
My proposition (es6) - "code from head":
[
"newFloorplan",
"showOpenWindow",
"saveFloorplan",
"saveFloorplanAs",
"showRemoveWindow",
].map(id=>document.getElementById(id).addEventListener('click', event=>
filesystem[id]();
event.preventDefault()
));
My proposition (es6) - "code from head":
[
"newFloorplan",
"showOpenWindow",
"saveFloorplan",
"saveFloorplanAs",
"showRemoveWindow",
].map(id=>document.getElementById(id).addEventListener('click', event=>
filesystem[id]();
event.preventDefault()
));
answered Dec 1 '18 at 19:26
Kamil KiełczewskiKamil Kiełczewski
14.4k87397
14.4k87397
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322064%2fhow-to-simplify-multiple-functions-that-have-different-ids%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown