When objects are called, they are usually followed by a . that tells us a property or a method is about to be called. Let's hope this analogy works. Think of yourself as an object called you.
Now, you have properties about yourself. So, if I typed you.hairColor , I would expect the results to be whatever hair color you had. That is an object property in a nutshell.
The variable example is a string and one of its main properties is length. We get 7 because "Welcome" has 7 characters.
Methods are actions of or on the object. Again using you as an object, you.standUp() would make you stand up.
While the strike() method seems vicious, it simply just puts a line through the object string. Notice how the methods have () after them. Sometimes, they require arguments very much similar to functions. Our last example didn't require one, but now I'll show you what it looks like if they do.
The method charAt has an argument of 3, which is why it is shown above as charAt(3). The charAt goes through a string and finds which character is at a position in the string. Since, we used 3 as the argument, it returns "c" because c is the 4th character from the left. Remember that most methods start from 0. So, charAt(0) would return "W".
As you can see reference an object's id is very common, but sometimes it is better to reference an object's name.
Your code will execute in this window.
Let's explore some more tutorials or topics!
Edward April 13, 2015, 3:28 a.m.Referencing the last example, the document.getElementsByName method returns an array of objects. The syntax should be: document.getElementsByName("example2").innerHTML = "Changed Text";
Charlie April 29, 2014, 3:22 p.m.The last example, document.getElementsByName() doesn't work. Please have a check. Thanks, Charlie
kurama3 Feb. 17, 2014, 1:18 a.m.I like the use of the reference 'you' when describing objects. If only there was a you.goToSleep()