4 ms·
This is clever! My solution has always been something to the tune of: var kyle = Person.getByName("kyle"); But your solution is better in that the interf
by dorkitude 14y ago
This is clever!
My solution has always been something to the tune of:
var kyle = Person.getByName("kyle");
But your solution is better in that the interface need not change (there could be a lot of code to rewrite in my case, if the "new" keyword were already being used everywhere).
I do like it that in your solution the interface is (or remains) elegant, but I can't help but think, as a pythonista at heart, "explicit is better than implicit". So I'm little freaked out by the idea that code reading:
var kyle = new Person("kyle");
isn't actually constructing a new instance.
- masklinn 14y agoThen again, the equivalent Python code does not at all guarantee it'll return a new object, and it's a very good use case for returning objects from JS constructors.