Beginner JavaScript Tutorial – 27 – Adding Methods to Our Objects

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

24 responses to “Beginner JavaScript Tutorial – 27 – Adding Methods to Our Objects”

  1. Bikash Majumdar Avatar

    Why isn't my browser processing this ?
    ?

  2. Sheni Hamitaj Avatar

    this syntax is … so alienish

  3. TheWeakHero Avatar

    i did:
    function people(year) {
    this.year = year;
    this.yourage = getage;

    }

    function getage() {
    return 2017 – this.year;

    }

    var hamid = new people(2002);

    document.write(hamid.yourage);

    it gave me this error at the browser pls help:
    function getage() { return 2017; }

  4. Albert Chan Avatar

    Ummm… Why is yearsLeft() not encapsulated (not even sure if it's the right term) inside people class ?
    from my experiment, not putting yearsLeft() inside people class function means that function yearsLeft() can be called from anywhere by anyone, and thus creating unexpected and undesirable result—especially when playing with "this" keyword.
    putting yearsLeft() inside people class straight up preventing other irrelevant things from accessing yearsLeft() function without instantiating people class first.

  5. Shashwat Dahal Avatar

    I don't know whats going on the 100 is not subtracting this.agehere is what I did<html>
    <head>
    <script type="text/javascript">
    function people(name,age){
          this.name = name;
       this.age = age;
       this.YearsUntilDeath = yearsLeft;
    }
         function yearsLeft(){
      numYears = 100 – this.age;
      return = numYears;
      }
     
      var youtube  = new people("Youtube channel" , 70);
    </script>
    </head>
    <body>
    <script type="text/javascript">
    document.write(youtube.yearsUntilDeath());
    </script>
    </body>
    </html>

  6. dzamija922 Avatar

    This guy's really got some issues with phlegm.

  7. Bill Beds Avatar

    your code is wrong.

  8. MaxE Production Avatar

    Can you do this.yearsLeft = yearsLeft? Or do they have to be different in this case?

  9. E. F. Avatar

    What's wrong with this code? I keep getting the lines of code from function UrAgeMinusFive?

    function person(name, age) {
    this.name = name;
    this.age = age
    this.age2 = UrAgeMinusFive;
    }

    var a = new person("Bill", 25);
    var b = new person("Mark", 28);

    function UrAgeMinusFive() {
    var MinusFive = this.age – 5;
    return MinusFive
    }
    alert(a.age2)

  10. Bishwanath Yengkhom Avatar

    hey Bucky I have a question why you are yearuntilRetire () … paranthesis .. will u please elaborate

  11. De'von Mackey Avatar

    Where the parameters added to the document.write statement because yearsUntilRetire is = to a function() ???

  12. The Shroom Avatar

    Seems like a weird attempt at implementing classes lol

  13. Mike Putz Avatar

    A suggestion to anyone who watched this once (or twice). Try explaining it while you type out the code. After one go through, I emailed my dad and explained what each line meant. Why you use 'this.property', why you don't use parenthesis for 'yearsUntil' in the constructor etc. I had to sneak a peak a few times. Then watch the video again, taking notes. Finally, try doing it yourself without cheating. After the first watch through I was a bit lost, but 20 minutes later, 2 times watching it, and 3 times writing the code I feel more confident. Good luck everyone!

  14. lax Kan Avatar

    For

    this.yearUntillRetire = yearsLeft;

    you dont need a braces here because it is a DELEGATE. "yearsLeft" is called a delegate, you can think it as a Function Variable(variable that represents a function). It can also be passed around like variables and any delegate that it was assigned to can be used as a function and that could result in "yearsLeft"' function to be called

  15. lax Kan Avatar

    Dude I liked your Tutorial.. easier than reading a book. Which these days are becoming fatter and fatter.. like people. I didn't want to discourage you but official defining an object is mentioned as something like this. firstName, lastName are properties and fullName is a method

    var person = {
    firstName: "John",
    lastName : "Doe",
    id : 5566,
    fullName : function() {
    return this.firstName + " " + this.lastName;
    }
    };

    of course there are many ways to define an object

  16. WolvesFanVideos Avatar

    really could do with learning this shit but its so hard

  17. chiranjib mukherjee Avatar

    I didn't understand why haven't you put parenthesis when you assign this.yeaUntilRetire= yearLeft and you put parenthesis when you call yearLeft in body. Can anyone plz help me .

  18. Erika Nygard Avatar

    I think you are a good teacher. Thank you for helping me understand this all better.

  19. darkFo3 Avatar

    Fahrenheit, Kelvin… He forgot calculus XD

  20. Marija Jakovljevic Avatar

    Thank you for not making this a monster. Simple well understandable language, I like it! Keep up 🙂

  21. kkevin369 Avatar

    i thought functions didn't have scope with one another

  22. Vincent Lim Heng Yip Avatar

    Can i ask a question?
    this.yearsUntilRetire = yearsLeft; // why there is not a bracket yearsLeft() .Is it mean that if we call a function without input any parameter ,so no need to put () ?

  23. L M Avatar

    Wow now it piece of cake to learn the complexity data types behind function & objects thank Bucky you save me from a brain seizure 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *