ksd123
asked on
Accessing functions in javascript
Hi Experts,
I want to access functions defined in javascript file (foo.js) from sample.js file. These javascript files reside in the same folder.
I want to access functions defined in javascript file (foo.js) from sample.js file. These javascript files reside in the same folder.
[subtitle]foo.js[/subtitle]
function foo() {
}
foo.ftype.Isempty=function(){
}
//Returns a value in specific format
foo.Telformat=function(param){
}
//Returns true / false
foo.ValidateTel=function(param){
}
//Returns true / false
foo.Isnumber=function(param){
}
[subtitle]sample.js[/subtitle]
function testall (someparam)
{
//Here I need to call foo.js file helper functions
}
ASKER
Basically foo.js contains generic functions that will return boolean / some values.So in the sample.js file I have a function called testall and want to invoke generic fucntions.
sample.js
sample.js
function testall (someparam)
{
//Here I want to invoke / call the functions defined in the foo.js file
}
if you load the scripts as suggested in my first post, there's no problem
ASKER
I did n't get you. I am c# developer ,suppose if I have a class (common.cs) and have methods for Format,reverse of string,Isnumber etc. I can invoke these methods in other classes .In sample.cs file to access common methods , I will instantiate common class and pass parameters to these methods as required.In javascript ,How can I achieve this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Mat be my question is not clear,let me put in this way actually I am doing model validation in angularjs and checking user input is valid or not.Suppose if user enter's invalid data in the text box and have a function in sample.js file that takes input data from form and checks valid or invalid.To do this I want to invoke common methods(IsNumber,ValidateT el etc) and return true (no msg) or false (Show error msg in the UI).In this case, I don't have to do anything?
This page http://docs.angularjs.org/tutorial/step_02 shows part of how angularjs is used. It show including the necessary javascript files in the web page so that the application code has access to the functions that are needed. You do have to include the necessary files in script links so they will be loaded by the browser and be available.
ASKER
Thank you guys
Open in new window