Search the Community
Showing results for tags 'method'.
-
Hi, I'm studying a constructor function pattern. I have made this constructor: function Person( firstname, age, place ) { this.firstname = firstname; this.age = age; this.greeting = { Hello: function(){ console.log( "Hello " + firstname ); }, YouAre: function(){ console.log( "You are " + age + " years old"); } } this.greeting2 = { Hello: function(){ console.log( "Hello " + this.firstname ); }, YouAre: function(){ console.log( "You are " + this.age ); } } } Person.prototype = { greeting3: { Hello: function(){ console.log( "Hello " + this.firstname ); }, YouAre: function(){ console.log( "You are " + this.age ); } } } var Clara = new Person( 'Clara', '20' ); Clara.greeting.Hello(); // Hello Clara Clara.greeting.YouAre(); // You are 20 years old Clara.greeting2.Hello(); // Hello undefined Clara.greeting2.YouAre(); // You are undefined Clara.greeting3.Hello(); // Hello undefined Clara.greeting3.YouAre(); // You are undefined On the greeting2.Hello and greeting2.YouAre methods, 'this' name and age result is undefined, the same with greeting3 method. The question is: How do we get a property value through a method inside an object array? and who is 'this' in greeting2 and greeting3 functions? Thanks!
- 11 replies
-
- constructor
- prototype
-
(and 1 more)
Tagged with:
-
Hello, while reading the tutorial about js i found this paragraph: According to Stack Overflow fullName is not a function, because the result depends on the state of the object and is not always the same. Maybe you need to correct this or be more precise with your definition of a function.
-
- javascript
- js
-
(and 2 more)
Tagged with:
-
Hi all, Im pretty much a noob to javascript. I try to get how the statements work together. if you have a javascript command like this: document.all.myFile.innerText Then document is an object and so is all myFIle is a variable but what is innerText ? Is that a property or a method? Are there any obligations in writing these commands? like this: object.subobject.property.method? Or are you free to use these through each other?
- 2 replies
-
- javascripy
- propert
-
(and 3 more)
Tagged with:
-
Hello, im wondering how does jQuery get method work. Since it should not reload the page again? I've seen this, but how to example make this more automated whitout refreshing "http://mudsaf.info/games/index.php". $.ajax({ url: url, data: data, success: success, dataType: dataType});
-
I am developing a function to find a particular element within another element identifier (similar to getElementById but that applies to any other element) ... Because this throws me arror: var ancestor = document.getElementById('divAncestor');var child = ancestor.getElementById('divChild'); I know, HTML specifies that ids must be unique but reality proves that often running scripts that can have items with the same ids. So, thats the reason why I'm not simply calling the child like this: var ancestor = document.getElementById('divChild'); The first option was to add this function to each HTML element, or at least the divs (because that's what interests me identify). The second, and is the one I prefer, is to add a method to the document object and call from there by passing the ID of the father and son as parameters. Is this possible?Thanks for your time.