Calling javascript functions from separate file

Thread is closed for posting
2 posts, 0 answers
  1. Anupam
    Anupam avatar
    3 posts
    Member since:
    Nov 2014

    Posted 07 Dec 2014 Link to this post

    Hello. I have created a Kendo UI core widget project. I have created a viewmodel source code as home.js. want to create a separate javascript functions file containing some common functions required for app. How can I refer tghe functions of these files in home.js.

    Please advice.
  2. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 10 Dec 2014 Link to this post

    Hello Anupam,

    In order to use your common functions in home.js you need to make sure that you link the common JavaScript file in the app, before you link the home.js file. For instance if you have a common.js containing the following code snippet:
    var Common = {
        sayHello: function() {
    function sayGoodbye(){

    as long as you link this file before the home.js file in index.html:
        <meta charset="utf-8" />
        <link href="kendo/styles/" rel="stylesheet" />
        <link href="styles/main.css" rel="stylesheet" />
        <script src="cordova.js"></script>
        <script src="kendo/js/jquery.min.js"></script>
        <script src="kendo/js/"></script>
        <script src="scripts/common.js"></script>
        <script src="scripts/home.js"></script>

    You can invoke the sayHello() and sayGoodye() functions in home.js like this:

    There are multiple tutorials around the web that can help you get started with that. You can also explore the concept of JavaScript namespaces and modules. On that topic you can also find multiple tutorials around the net.

    Tina Stancheva

    Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

Back to Top