2

If I have this code in a file called custom.js:

var kennel = function(){this._init();};

kennel.prototype = {
    _init: function() {
        this.setListeners();
    },
    setListeners: function(){
        ...
    },
    getCats: function(){
        alert("Get cats");
    }
};

How do I call getCats() from some arbitrary html file?

2 Answers 2

3

First of all you would include the javascript by using the <script> tag, generally in the <head>, then after that you can create another <script> tag which you can place your own javascript code in that is specific to the page, and which uses the functionality made available by the included file. For example:

<head>
    <script type="text/javascript" src="path/to/custom.js"></script>
    <script type="text/javascript">
        var myKennel = new kennel();
        myKennel.getCats(); // alerts "Get cats"
    </script>
</head>

Also, the code you have posted has nothing to do with jQuery - it is plain old, vanilla javascript.

Sign up to request clarification or add additional context in comments.

Comments

1

This should be enough:

<script>
  var k = new kennel();
  k.getCats();
</script>

Here's a sample of it working: http://jsfiddle.net/NHaBb/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.