Javascript constructor behaviour -


I have a question regarding the JS constructor function. I have the following code:

  var PersonConstructorFunction = function (first name, last name, gender) {this.personFirstName = firstName; This.personListName = lastname; this.person gender = gender; this.personFullName = function () {return.personFirstName + "" + this.personListName; }; this.personGreeting = ceremony (person) {if (this.personGender == "male") {return "hello shri" + this.personFullName (); } And if (this.person gender == "female") {return "hello misses" + this.personFullName (); } And {return "Hello there!"; }}; }; var p = new public control functions ("Donald", "Duck", "Male"); P2 = new person control function ("Lola", "Bunny", "Women"); document.write (p2.personGreeting (p2) + "");   

The result is very clear - - Hello Mrs. Lola Bunny -

The question is: There are two equal objects and the properties and methods P2 with the same number when I call the person's greeting method and pass the second object as the argument, then I can not understand the following behavior:

  ** document.write (p2.personGreeting (p) + ""); **   

In this case, I receive - Hello Mrs. Lola Bunny - , but what about the P object is passed in the form of logic?

The person gets the greeting of the person greeting, determines his gender, and the BSD shows the congratulations on the result.

Resally I learned C # and the constructors work there equally.

You are not doing anything with the passed parameters Since you are using this , only the variables within your constructor are being called.

You can person. PersonFullName (); and this will mean that the parameter member will be called personFullName () and not your constructor

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -