0
Blog.prototype.signature = "TEXT"

did this statement here created a signature variable?

because this statement didnt have var keyword in it.

Also additional question

why need to use function literals or function reference to make a function inside the prototype of an object?

ex. this wont work....

obj.prototype.toString{

    return "dfasdfa";

}
user1393669
  • 43
  • 1
  • 2

1 Answers1

1

did this statement here created a signature variable?

No, it set a property on the prototype of the Blog class.

why need to use function literals or function reference to make a function inside the prototype of an object?

Because you need to assign something to the property obj.prototype.toString. You have to set it to equal something (in this case, function), which you're not doing with the code snippet you displayed.

Example:

obj.prototype.toString = function() {
    return "dfasdfa";
}

Note that you're actually assigning a value to that property with the = function bit. Then you go on to declare the function later on.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Elliot Bonneville
  • 51,872
  • 23
  • 96
  • 123
  • Nope. The key word here is `property`. You're setting a *property* on an object, as opposed to creating a variable. – Elliot Bonneville May 14 '12 at 23:48
  • @user1393669: You have a variable "Blog" (which seems to be a function). Then you [access](https://developer.mozilla.org/en/JavaScript/Reference/Operators/Member_Operators) the object on the "prototype" property and assign a new value to its "signature" property. – Bergi May 15 '12 at 00:52
  • @ElliotBonneville: To be correct, that is not a *function declaration*, but a *function expression*. – Bergi May 15 '12 at 00:56
  • @Bergi: Is that so? What is the difference? – Elliot Bonneville May 15 '12 at 01:53
  • @ElliotBonneville: [What is the difference between a function expression vs declaration in Javascript?](http://stackoverflow.com/q/1013385/1048572) – Bergi May 15 '12 at 02:12