I'm going to guess that your first code block was meant to look like this:
function xyz(){
this.callXyz = function(){
console.log('callXyz inner');
}
}
And I'm going to assume you do new xyz
at some point to create an instance.
If so, the difference is that in that first example, a new function is created each time xyz
is called (presumably via new
) and assigned as an own property on the new object. In the second example, the function is only created once, and then the new object created by new xyz
gets that property as an inherited property from its prototype; all of the instances created via new xyz
share the same function.