What does the author refer to as "newly created object" in this code?

This is part of Ryan Frishberg’s article on JavaScript: http://www.sitepoint.com/oriented-programming-1/

function myFunc(StringValue){  <br>
      this.StringValue = StringValue;  <br>
    }  <br>
      <br>
    var myObject = new myFunc("This is myObject's string");  <br>
    var myObject2 = new myFunc("This is a String");  <br>
    alert(myObject.StringValue); // displays "This is myObject's string"  <br>
    alert(myObject2.StringValue); // displays "This is a String"

He writes, “In the myFunc() constructor, this.StringValue refers to the property being assigned to the newly created object, while StringValue refers to the function’s local variable that was passed as an argument.”

What does he refer to as “newly created object”?

With the following code:


 var myObject = new myFunc("This is myObject's string");

The myObject variable contains the newly created object.

So with the myFunc constructor, where it uses this.StringValue will result in the myObject variable having a property called myObject.StringValue

I would rewrite the code so that it follows standard coding conventions where only the constructor function has a capital first letter and all other variables do not, for example:


function Kitten(name) {
    this.type = 'cat';
    this.name = name;
}

var kitten = new Kitten('Socks');
alert(kitten.name); // displays 'Socks'

I would rewrite the code so that it follows standard coding conventions where only the constructor function has a capital first letter and all other variables do not, for example:


function Kitten(name) {
    this.type = 'cat';
    this.name = name;
}

var kitten = new Kitten('Socks');
alert(kitten.name); // displays 'Socks'

Thanks. BTW, does

this.name = name;

say that the new constructor (new Kitten) will have the same name as function Kitten?

It says that the new object being created will have a property called name, which is assigned the value of name which is passed in to the constructor.

So:


var kitten = new Kitten('Socks')

results in ‘Socks’ being passed as a parameter to the Constructor function called Kitten, so that in:


[function Kitten(name) {
    ...
}

the variable called name is now the string ‘Socks’

When this next line of code is executed


this.name = name;

The this keyword refers to the object being constructed, and this.name is a property of that object that we are assigning a value to, that value being ‘Socks’

Thanks.