I have showNewWindow, showNewWindowSuccess functions in one js file
and I have openNewWindow function in another js file,
I am trying tto remove the showNewWindowSuccess function from my
success function
but I am getting the following error, Uncaught TypeError:
sports.util.Utils.openNewWindow is not a function
can you guys tell me how to fix it
providing my code below
showNewWindow: function(menu) {
var me = this,
newWindowId = sports.util.Utils.randomString(12);
To declare a function in javascript you need this sintax:
function openNewWindow(param1, param2, param3){
//Do something here...
};
Related
I am facing one problem
I am trying to call document.ready() function inside another JavaScript function but when I am calling it, it says "function is not defined
Here is my code :
this is first function that is document.ready() function
$(document).ready(function ExpandMessageBox() {// this is my document.ready function. I have given the name of it as "ExpandMessageBox"}
this is another regular JavaScript function in which I am trying to call above function
function ShowMessageBox() {
ExpandMessageBox();}
But this is giving me an error as :
"Uncaught ReferenceError: ExpandMessageBox is not defined"
Where I am doing wrong...
Please Help
Tons of thanks in advance
You need to define ExpandMessageBox function in the common scope. Something like this:
function ExpandMessageBox() {
//your staff
}
function ShowMessageBox() {
ExpandMessageBox();
}
$(document).ready(ExpandMessageBox);
The below code snippets are not the actual code, they are only there to explain my issue. So please don't concentrate on the actual functionality. I'm working with Adobe DTM. I have no idea how to get an anonymous function that returns a value (as a Data Element to source a global function? If I have a normal anonymous function within my data Element, everything works fine. If the anonymous function returns, then it doesn't work? Is there any way to get this to work? Example:
//global function
function _myGlobalFunct(str){
return (str);
}
the following code of an anonymous function within the Data Element calls global function and it works as expected:
// working anonymous function
(function () {
window._myGlobalFunct("value1");
})()
but the following return anonymous function, within the Data Element, doesn't call my function but doesn't throw any errors? :
// Not Working Properly but doesn't throw any errors?
return (function() {
var rvalue = document.title || "No Title";
window._myGlobalFunct(rvalue);
return rvalue;
})();
I do know the function is executing but not getting any errors in Chrome?
DTM's data elements execute the code provided within a function (that may not be clear to the other users here), so there will be a return outside of a function in the code you input/show here. You're not returning the value from your function (or if you're trying to update rvalue within the function and rvalue isn't in the right scope (window vs. local)). In any case, is there a reason you're using the anonymous function anyways? Below should work:
var rvalue = document.title || "No Title";
return window._myGlobalFunct(rvalue);
If you still want the anonymous function, make sure to grab the return value from your function:
return (function() {
var rvalue = document.title || "No Title";
return window._myGlobalFunct(rvalue);
})();
I don't think you can return a self-invoking function and then return again in the function.
Since I can't comment yet I will explain it here in more detail, why it is indeed a duplicate. The first answer by Niet the Dark Absol in the link I mentioned above(for reference: Syntax error: Illegal return statement in JavaScript), clearly says the following:
return only makes sense inside a function. There is no function in
your code.
To apply this to your case:
return (function() {
Is your first line, if you would encapsulate everything in another function and call that one everything will be working fine, e.g.:
function myFunction(){
return (function() {
var rvalue = document.title || "No Title";
window._myGlobalFunct(rvalue);
return rvalue;
})();
}
And then you can call myFunction() to get your return value. I hope this helps you out.
The code inside the controller is:
(function(){
$scope.show();
profile.friend_requests_to_me_service(loggedInUser.id).then(function(data){
console.log(data);
$scope.friend_requests_to_me = data.data.friend_request_to_me;
$scope.friends = data.data.people_you_may_know;
$scope.hide();
});
})();
As you can see this function is calling the service profile and a method of that service.The problem is that this invoking function is not working.The error is given:
TypeError: (intermediate value)(...) is not a function.In plunker i have checked a trivial self invoking function.Here is the link:http://jsfiddle.net/Lvc0u55v/4582/.
This trivial self invoking function is working.But I cant understand why my actual app self invoking function is not working.Thank you for your time.
The present working version(non self invoking) is:
$scope.friendship_requests_to_me_function = function(){
$scope.show();
profile.friend_requests_to_me_service(loggedInUser.id).then(function(data){
console.log(data);
$scope.friend_requests_to_me = data.data.friend_request_to_me;
$scope.friends = data.data.people_you_may_know;
$scope.hide();
});
}
$scope.friendship_requests_to_me_function();
Most probably one of your js statement is missing a ';' at the end.
Try add a ';' before your self invoking function.
Read more here
We end up passing the second function as an argument to the first function and then trying to call the result of the first function call as a function. The second function will fail with a "... is not a function" error at runtime.
i'm following along a book and I have 2 javascript files. Both are in the HTML file as:
<script src="playlist_store.js"></script>
<script src="playlist.js"></script>
however, when I try to call a function from playlist_store.js inside of playlist.js chrome debugger says "uncaught reference error. loadPlaylist is not defined. loadPlaylist() is the function from playlist_store.js
I thought there might be a typo somewhere but I don't think there is. Does playlist.js actually need to somehow import or include / require the playlist_store.js ? Is the browser not smart enough to somehow link them so the functions in one you can call from another?
Defining a function like follows
function myaction () { }
is a named (private) function.
It is better to write a (private) function assigned to a variable:
var myaction = function () { };
Now what you need is a function, that is assigned to a variable in the global object:
myaction = function () { };
// or strict:
window.myaction = function () { };
It is now a global (public) function, so you can use it outside of your defining .js.
Beware that the first example, a function statement doesn't have a semicolon. Using the function operator as in the other examples, you need a semicolon.
I have the following code using actionscript and the indesign sdk:
At the beginning of my Class
[ Embed (source= "resources/js/eventHandlers.jsx" , mimeType= "application/octet-stream" )]
private static var jsHandler:Class;
var jsxInterface:HostObject = HostObject.getRoot(HostObject.extensions[0]);
In my function:
jsxInterface.eval( new jsHandler().toString());
jsxInterface.init( this );
document.xmlElements.item(0).xmlElements.item("docpreset").importXML(File.applicationStorageDirectory.resolvePath("temp/cstyles.xml"));
jsxInterface.afterImport(document);
this is the code inside eventHandlers.jsx:
var asInterface = {};
function init(wrapper) {
asInterface = wrapper;
}
function afterImport(document) {
document.addEventListener (Document.AFTER_IMPORT, asInterface.test());
}
and from javascript I call this:
public function test():void {
trace("ole");
}
Now, the test function gets executed correctly, but after that the next thing that gets called is again this:
jsxInterface.afterImport(document);
and then an error is thrown:
Error: ActionScript error: Error: Missing required parameter 'handler' for method 'addEventListener'.
I have no idea anymore on what I need to do. All I want is for the xml to be imported and an event dispatched when the import is complete.
I have no idea why I even have to call a javascript function, and can't use the document.AFTER_IMPORT inside a normal eventListener. Can anyone help me out on this one please?
The problem seems to be that in your afterImport() method, you are adding the event listener incorrectly.
The second parameter to the addEventListener() method should be the name of a function (technically it's a reference to a function). In your code, you have put parentheses on the end of the function name -- so instead of providing the reference to the function, the function is being executed.
When the function executes, it returns nothing, so the second parameter to addEventListener() is missing and you get the error.
Try this instead:
function afterImport(document) {
document.addEventListener (Document.AFTER_IMPORT, asInterface.test);
// notice no "()" here ^^
}
[Edit]
Since you are still getting the error, you might want to add some code to debug it further.
In the method above, comment out the addEventListener line, and replace with something like this:
// for debugging
if (asInterface.test == null)
{
trace("fail: it's null");
}
else if (asInterface.test is Function)
{
trace("success: it's a function");
// this is the only code path where your error will not occur
}
else
{
trace("fail: i don't know what this is: ", asInterface.test);
}
I think you have to initiate the AS wrapper like this :
jsxInterface.init( this );
then the AS API becomes available to the js code.
Loic