I was looking at the code of the new
operator in the Douglas Crockford series.
function Shane(name){
this.name = name;
}
var sha = new Shane("name");
console.log(sha);
The above code just creates a new Shane object and sets its constructor to Shane and Prototype to Object.prototype:
function new(func, args){
var that = Object.create(func.prototype);
result = func.apply(that, args);
return (typeof result==='object' && result) || that;
}
Can anyone explain me on what this code does and give me an example for it?