0

Im trying to run the below script to understand the Javascript object and inheritance but don't see anything being displayed.

<html>
    <head>
        <script>
            $(document).ready(

                function Person(){
                    alert('New Person Created');
                }


                Person.prototype.sayHello = new function(){
                    alert('Hello');
                };

                var x = new Person();
                x.sayHello();

                var newfunction = x.sayHello;
                newfunction.call(Person);

            );
        </script>
    </head>
    <body>
    </body>
</html>
1
  • You should get used to spotting errors in the log, that’s your first lesson :) Commented Dec 10, 2013 at 21:24

4 Answers 4

1

$ is defined in jQuery, you need to include jQuery library before using the $

you can include jquery library using cdn like this,

<script src ="//code.jquery.com/jquery-1.10.2.min.js"></script>
Sign up to request clarification or add additional context in comments.

Comments

0

The first line of your script is jQuery. If you want to use jQuery you should include it first (based on what you have written I strongly suspect you don't need or want it just yet).

Alternatively, just drop the $(document).ready part and its {}s and that should get you going.

Also, take a look at your developer tools menu and get your JavaScript console open. It will have told you about this error.

Comments

0

When you use a construct like $(document), you are calling a function $, which is defined as jQuery. You need a <script> tag in your document to load the correct version of jQuery. Also, check your browser console. You will see an error there about $

Comments

0

The only thing I can see wrong is that you are trying to use the jQuery library, but you've never actually included it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.