It is valid.
Like the others have stated, there are no prototype related issues here.
You are attaching 2 propertyes to 2 different objects:
- the so called "static" function is attached to the function definition (F)
- the so called "public" function is attached to the object returned by the constructor (new F())
So, since F !== new F(), they are 2 different thing with different props.
If you want to make use of the prototypal inheritance, you can consider the following example:
var F = function(){}
// function visible to all of F's instances
F.prototype.f1 = function(){console.log("I'm inherited!");}
// a so called "static" function
F.f1 = function(){console.log("I'm static!");}
var instance1 = new F();
var instance2 = new F();
// function visible only to this instance of F
instance1.f1 = function(){console.log("I'm visible only to this instance of F");}
f1()invar F = function(){ this.f1(){...} }was identical toF.prototype.f1 = function(){...}F.prototypeis one object from which all new objects will inherit. But withthis.f1 = ...you are assigning the function to each new element (each element has its own function). It will look the same but the object structure is different. Have a look at the output (console) of this example: jsfiddle.net/fkling/5ewLe