Javascript Prototyping Question
- by Nick Lowman
I'm just reading about Prototypes in JavaScript and Douglas Crockford offers and excellent way to select a new objects prototype but can anyone explain (below) why obj01's type equals 'object' when I pass it in function as it's prototype?
if (typeof Object.beget !== 'function') {
Object.beget = function (o) {
console.log(typeof o);//function
var F = function () {};
F.prototype = o;
console.log(typeof F);//function
return new F();
};
}
var func01 = function(){};
var obj01 = Object.beget(func01);
console.log(typeof obj01);//object
console.log(typeof obj01.prototype);//object
I thought it would be
console.log(typeof obj01);//function
console.log(typeof obj01.prototype);//function