JS : décomposition d'un new


11 juillet 2011

Voici ma version d'un new en JS :

operator    new(Constructor)        {
    var Instance = {}
    Instance.constructor = Constructor
    Instance.prototype = Constructor.prototype
    var RetVal = Constructor.apply(Instance)
    return typeof RetVal == "undefined" ? Instance : RetVal
}

�a permet de comprendre facilement le langage et sa manière d'opérer.

Accueil