Jump to content

Search the Community

Showing results for tags 'constructor'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 3 results

  1. Hello - first time posting. I've searched the forums to see if anyone else had the same question, with no luck. I'm going through the lessons in the tutorial but I can't figure out what's going on in part of the JS Type Conversion lesson. I'll link to the full lesson here, but below is the part I'm having trouble with: (mainly the function) I have no idea what's happening in the function... could someone be kind enough to break it down in detail for me? I understand how arrays work. But the function here has me stumped. Thanks so much
  2. 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!
  3. Hi, I made a constructor function and wrap it like in IIFE (immediately invoke) style. I create addPerson as a command to call the function. All works fine. But when I use var to create addPerson, it returned undefined. What is the difference between using var and not? (function (){ function Person( firstname, age, place ) { var elem = this; 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( "2. Hello " + elem.firstname ); }, YouAre: function(){ console.log( "You are " + elem.age + " years old" ); } } } addPerson = function(firstname, age){ var ab = new Person(firstname, age); return ab; }; /* // If I use "var" to create a new variable, // the "addPerson" returned undefined when I call it. // Why this happened? var addPerson = function(firstname, age){ var ab = new Person(firstname, age); return ab; }; // Not working! */ }()); Calling the Person function: var Clara = addPerson( 'Clara', '20' ); var Jason = addPerson( 'Jason', '24' ); Clara.greeting.Hello(); Jason.greeting.Hello(); Thanks!
×
×
  • Create New...