Beginner JavaScript Tutorial – 25 – Creating Our Own Objects




Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts

Original source


43 responses to “Beginner JavaScript Tutorial – 25 – Creating Our Own Objects”

  1. FYI-
    'this' is only for the contextual reference of an object and can be used as a pronoun(in a way)
    imagine this sentence: Bucky is a good man. Bucky likes to code….?
    So in programming world, 'this' keyword provides simplicity along with what all Bucky has mentioned.

  2. Sorry buddy!
    But just conceptually you were very wrong.
    Actually what you have defined is not an object but a class. And what you are calling an "instance of an object" is actually an "instance of a class". Object is itself an "instance of a class". Not that you are teaching wrong coding. Your lectures are good. But its just that the nomenclature you just used at the end was quite wrong. Hope you can correct it now!

  3. <!doctype.html>
    <html>
    <head>
    <script type="text/javascript">
    function a(fname,lname,age)
    {
    this.fname=fname;
    this.lname=lname;
    this.age=age;
    }

    </script>
    </head>
    <body>
    <script type="text/javascript">
    var x= new a("ana","cheri",28);
    var y= new a("margot","robbie",28);
    var z= new a("leo","messi",29);

    document.write(x.fname + x.lname + x.age +"<br/>");
    document.write(y.fname + y.lname + y.age +"<br/>");
    document.write(z.fname + z.lname + z.age +"<br/>");
    document.write(x.length+ y.length + z.length +"<br/>"); // why it's showing undefined ..??
    </script>
    </body>
    </html>

  4. I did:
    <html>
    <head>
    <script type="text/javascript">
    function person(name, age){
    this.name = name;
    this.age = age;
    }

    var Nick = new person("Nicholas Noriega", 23);
    var Taylor = new person("Taylor Swift", 20);
    </script>
    </head>
    <body>
    <script type="text/javascript">
    document.write(Nick.name);
    document.write(Taylor.age);
    </script>
    </body>
    </html>

    And only My name popped up as Nicholas Noriega23… How do I display two?

  5. would you really say it is stupid to use "this" in this context? to me it's the clearest example of "this". I mean, "this" has a lot if misinterpretations, but I wouldn't say this is one of it. how would you select the current object if not?

  6. Guys, I rage-quited at this tutorial about 3 months ago. Now I came back to learn some stuff, but I don't remember anything I have learned about HTML, CSS and JavaScript already. lol Wish me luck cause I want to become the best JavaScript programmer in the world ๐Ÿ˜€

  7. Can't speak about JavaScript instructors as I'm self taught with that, but objects don't need instantiation. It's classes that need instantiation, but even if objects in JavaScript are synonymous with classes, it's to avoid confusion between the following:

    "I'm going to create a new object to handle the data."

    …did I just say I need a new instance to handle the data, or am I writing new code to handle the data? You don't really know, and ambiguity in programming is the fastest way to Bugsville. So:

    "I'm going to create a new object…" means "I'm going to write code…"

    and

    "I'm going to instantiate the object…" means "I'm going to USE an object…"

    There really is a reason for it beyond "giving your professor a hard on."

Leave a Reply