Scoping issue - calling an internal dojo function from external function
I have a function that is outside of the require portion of the dojo functions.
This function needs to call a function that resides within the dojo require block.
How do i call a function that is within the require code block from a function that resides outside the dojo require block?
Perhaps a little more application flow will demonstrate the need
- Main window application spawns a child window
- Main window sends a message to the child window that has a global function that will receive the message
- Child window receives the message
- The external function parses the message and determines that the map
needs to be updated (The child window that is spawned is the mapping window and loads a lot of ESRI modules in the require section) - the child window function needs to call a function that is
within the require code block of dojo to do the actual ESRI related tasks
javascript dojo esri-javascript-api
add a comment |
I have a function that is outside of the require portion of the dojo functions.
This function needs to call a function that resides within the dojo require block.
How do i call a function that is within the require code block from a function that resides outside the dojo require block?
Perhaps a little more application flow will demonstrate the need
- Main window application spawns a child window
- Main window sends a message to the child window that has a global function that will receive the message
- Child window receives the message
- The external function parses the message and determines that the map
needs to be updated (The child window that is spawned is the mapping window and loads a lot of ESRI modules in the require section) - the child window function needs to call a function that is
within the require code block of dojo to do the actual ESRI related tasks
javascript dojo esri-javascript-api
posting some portion of code would hel , also , are you using sort of Iframe or , pupup window ?
– Boo Berr'ita
Nov 13 '18 at 6:43
add a comment |
I have a function that is outside of the require portion of the dojo functions.
This function needs to call a function that resides within the dojo require block.
How do i call a function that is within the require code block from a function that resides outside the dojo require block?
Perhaps a little more application flow will demonstrate the need
- Main window application spawns a child window
- Main window sends a message to the child window that has a global function that will receive the message
- Child window receives the message
- The external function parses the message and determines that the map
needs to be updated (The child window that is spawned is the mapping window and loads a lot of ESRI modules in the require section) - the child window function needs to call a function that is
within the require code block of dojo to do the actual ESRI related tasks
javascript dojo esri-javascript-api
I have a function that is outside of the require portion of the dojo functions.
This function needs to call a function that resides within the dojo require block.
How do i call a function that is within the require code block from a function that resides outside the dojo require block?
Perhaps a little more application flow will demonstrate the need
- Main window application spawns a child window
- Main window sends a message to the child window that has a global function that will receive the message
- Child window receives the message
- The external function parses the message and determines that the map
needs to be updated (The child window that is spawned is the mapping window and loads a lot of ESRI modules in the require section) - the child window function needs to call a function that is
within the require code block of dojo to do the actual ESRI related tasks
javascript dojo esri-javascript-api
javascript dojo esri-javascript-api
edited Nov 12 '18 at 17:48
asked Nov 12 '18 at 16:22
pithhelmet
97642149
97642149
posting some portion of code would hel , also , are you using sort of Iframe or , pupup window ?
– Boo Berr'ita
Nov 13 '18 at 6:43
add a comment |
posting some portion of code would hel , also , are you using sort of Iframe or , pupup window ?
– Boo Berr'ita
Nov 13 '18 at 6:43
posting some portion of code would hel , also , are you using sort of Iframe or , pupup window ?
– Boo Berr'ita
Nov 13 '18 at 6:43
posting some portion of code would hel , also , are you using sort of Iframe or , pupup window ?
– Boo Berr'ita
Nov 13 '18 at 6:43
add a comment |
2 Answers
2
active
oldest
votes
It's a hacky solution and you should really think of a way to rearrange your modules if possible, but this should at least work:
var inside = null;
function outside () {
try { inside(); }
catch (err) { /* log error or throw away, whatever */ }
}
require(['dojo/_base/declare', ..., 'your/module/function'], function (declare, ..., myModuleFunction) {
inside = myModuleFunction;
outside();
});
Just require the module which contains the function (named "your/module/function" and myModuleFunction in the example), store it in a variable outside of the require and call it in a function which has been defined outside already. I added a try-catch block because it is good measure and prevents your code from blowing up if you call outside too early.
In case the function inside the dojo require block isn't a module, it's almost the same:
var inside = null;
function outside () {
try { inside(); }
catch (err) { /* log error or throw away, whatever */ }
}
require(['dojo/_base/declare'], function (declare) {
inside = function () { console.log('Inside the require block'); };
outside();
});
Except that you don't have to require it.
Hi David - thanks for the reply... the myModuleFunction you described - would you elaborate on this function?
– pithhelmet
Nov 12 '18 at 17:17
myModuleFunctionis just a name which stands for the function inside your require block. The only reason I could think of why you cannot reach it without importing/requiring it is because it is a module (or part of a module) itself. Your question doesn't mention any names so I had to come up with something ;-)
– David
Nov 12 '18 at 17:30
add a comment |
Talk about a hack... here is what i did to get the results i needed.
I created a hidden button on the form, bound the click event to fire off the function.
When the message was received and processed, I fired off the button click event - and viola!!
thanks everyone for the help.
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%2f53266225%2fscoping-issue-calling-an-internal-dojo-function-from-external-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's a hacky solution and you should really think of a way to rearrange your modules if possible, but this should at least work:
var inside = null;
function outside () {
try { inside(); }
catch (err) { /* log error or throw away, whatever */ }
}
require(['dojo/_base/declare', ..., 'your/module/function'], function (declare, ..., myModuleFunction) {
inside = myModuleFunction;
outside();
});
Just require the module which contains the function (named "your/module/function" and myModuleFunction in the example), store it in a variable outside of the require and call it in a function which has been defined outside already. I added a try-catch block because it is good measure and prevents your code from blowing up if you call outside too early.
In case the function inside the dojo require block isn't a module, it's almost the same:
var inside = null;
function outside () {
try { inside(); }
catch (err) { /* log error or throw away, whatever */ }
}
require(['dojo/_base/declare'], function (declare) {
inside = function () { console.log('Inside the require block'); };
outside();
});
Except that you don't have to require it.
Hi David - thanks for the reply... the myModuleFunction you described - would you elaborate on this function?
– pithhelmet
Nov 12 '18 at 17:17
myModuleFunctionis just a name which stands for the function inside your require block. The only reason I could think of why you cannot reach it without importing/requiring it is because it is a module (or part of a module) itself. Your question doesn't mention any names so I had to come up with something ;-)
– David
Nov 12 '18 at 17:30
add a comment |
It's a hacky solution and you should really think of a way to rearrange your modules if possible, but this should at least work:
var inside = null;
function outside () {
try { inside(); }
catch (err) { /* log error or throw away, whatever */ }
}
require(['dojo/_base/declare', ..., 'your/module/function'], function (declare, ..., myModuleFunction) {
inside = myModuleFunction;
outside();
});
Just require the module which contains the function (named "your/module/function" and myModuleFunction in the example), store it in a variable outside of the require and call it in a function which has been defined outside already. I added a try-catch block because it is good measure and prevents your code from blowing up if you call outside too early.
In case the function inside the dojo require block isn't a module, it's almost the same:
var inside = null;
function outside () {
try { inside(); }
catch (err) { /* log error or throw away, whatever */ }
}
require(['dojo/_base/declare'], function (declare) {
inside = function () { console.log('Inside the require block'); };
outside();
});
Except that you don't have to require it.
Hi David - thanks for the reply... the myModuleFunction you described - would you elaborate on this function?
– pithhelmet
Nov 12 '18 at 17:17
myModuleFunctionis just a name which stands for the function inside your require block. The only reason I could think of why you cannot reach it without importing/requiring it is because it is a module (or part of a module) itself. Your question doesn't mention any names so I had to come up with something ;-)
– David
Nov 12 '18 at 17:30
add a comment |
It's a hacky solution and you should really think of a way to rearrange your modules if possible, but this should at least work:
var inside = null;
function outside () {
try { inside(); }
catch (err) { /* log error or throw away, whatever */ }
}
require(['dojo/_base/declare', ..., 'your/module/function'], function (declare, ..., myModuleFunction) {
inside = myModuleFunction;
outside();
});
Just require the module which contains the function (named "your/module/function" and myModuleFunction in the example), store it in a variable outside of the require and call it in a function which has been defined outside already. I added a try-catch block because it is good measure and prevents your code from blowing up if you call outside too early.
In case the function inside the dojo require block isn't a module, it's almost the same:
var inside = null;
function outside () {
try { inside(); }
catch (err) { /* log error or throw away, whatever */ }
}
require(['dojo/_base/declare'], function (declare) {
inside = function () { console.log('Inside the require block'); };
outside();
});
Except that you don't have to require it.
It's a hacky solution and you should really think of a way to rearrange your modules if possible, but this should at least work:
var inside = null;
function outside () {
try { inside(); }
catch (err) { /* log error or throw away, whatever */ }
}
require(['dojo/_base/declare', ..., 'your/module/function'], function (declare, ..., myModuleFunction) {
inside = myModuleFunction;
outside();
});
Just require the module which contains the function (named "your/module/function" and myModuleFunction in the example), store it in a variable outside of the require and call it in a function which has been defined outside already. I added a try-catch block because it is good measure and prevents your code from blowing up if you call outside too early.
In case the function inside the dojo require block isn't a module, it's almost the same:
var inside = null;
function outside () {
try { inside(); }
catch (err) { /* log error or throw away, whatever */ }
}
require(['dojo/_base/declare'], function (declare) {
inside = function () { console.log('Inside the require block'); };
outside();
});
Except that you don't have to require it.
edited Nov 12 '18 at 17:37
answered Nov 12 '18 at 16:54
David
46515
46515
Hi David - thanks for the reply... the myModuleFunction you described - would you elaborate on this function?
– pithhelmet
Nov 12 '18 at 17:17
myModuleFunctionis just a name which stands for the function inside your require block. The only reason I could think of why you cannot reach it without importing/requiring it is because it is a module (or part of a module) itself. Your question doesn't mention any names so I had to come up with something ;-)
– David
Nov 12 '18 at 17:30
add a comment |
Hi David - thanks for the reply... the myModuleFunction you described - would you elaborate on this function?
– pithhelmet
Nov 12 '18 at 17:17
myModuleFunctionis just a name which stands for the function inside your require block. The only reason I could think of why you cannot reach it without importing/requiring it is because it is a module (or part of a module) itself. Your question doesn't mention any names so I had to come up with something ;-)
– David
Nov 12 '18 at 17:30
Hi David - thanks for the reply... the myModuleFunction you described - would you elaborate on this function?
– pithhelmet
Nov 12 '18 at 17:17
Hi David - thanks for the reply... the myModuleFunction you described - would you elaborate on this function?
– pithhelmet
Nov 12 '18 at 17:17
myModuleFunction is just a name which stands for the function inside your require block. The only reason I could think of why you cannot reach it without importing/requiring it is because it is a module (or part of a module) itself. Your question doesn't mention any names so I had to come up with something ;-)– David
Nov 12 '18 at 17:30
myModuleFunction is just a name which stands for the function inside your require block. The only reason I could think of why you cannot reach it without importing/requiring it is because it is a module (or part of a module) itself. Your question doesn't mention any names so I had to come up with something ;-)– David
Nov 12 '18 at 17:30
add a comment |
Talk about a hack... here is what i did to get the results i needed.
I created a hidden button on the form, bound the click event to fire off the function.
When the message was received and processed, I fired off the button click event - and viola!!
thanks everyone for the help.
add a comment |
Talk about a hack... here is what i did to get the results i needed.
I created a hidden button on the form, bound the click event to fire off the function.
When the message was received and processed, I fired off the button click event - and viola!!
thanks everyone for the help.
add a comment |
Talk about a hack... here is what i did to get the results i needed.
I created a hidden button on the form, bound the click event to fire off the function.
When the message was received and processed, I fired off the button click event - and viola!!
thanks everyone for the help.
Talk about a hack... here is what i did to get the results i needed.
I created a hidden button on the form, bound the click event to fire off the function.
When the message was received and processed, I fired off the button click event - and viola!!
thanks everyone for the help.
answered Nov 13 '18 at 23:56
pithhelmet
97642149
97642149
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53266225%2fscoping-issue-calling-an-internal-dojo-function-from-external-function%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
posting some portion of code would hel , also , are you using sort of Iframe or , pupup window ?
– Boo Berr'ita
Nov 13 '18 at 6:43