I've been watching this video where Damian said that Crockford called it :" super constructor pattern"
Code sample : ( from the video)
var signalR;
signalR = function (url){
return new signalR.prototype.init(url);
}
signalR.prototype={
init:function(url)
{
this.url=url;
}
}
signalR.prototype.init.prototype = signalR.prototype;
Now, I've googled about Crockford and super constructor but all I could find is the implementation of Object.create
:
Which I understand pretty clear : ( also it's gotchas)
function create(o)
{
function f(){};
f.prototype=o;
return new f();
}
But still I don't see how it relates :
Question :
- What exactly (in the video) - did he try to solve by using this pattern? ( also small code sample will be much appreciated).
Lets see at normal class with constructor and prototype
so to generate a new instance of this class we have to write the following.
Lets look at Crockford
so to generate a new instance of this class we can write shortly the following to achieve the same like above.
seems that crockford is lazy to write lines, i'm thinking about pratical examples. but i think the whole thing is nothing exciting