I was playing around with JavaScript in particular simulating object oriented programming with classes and whatnot.
I knew about this way of achieving inheritance
<This is almost exactly what Object.create
does. The function you've written is a pretty standard "polyfill" for that method.
This is a really common way of abstracting object creation in a way that more closely reflects "true" prototypal inheritance. Definitely a safe way to do things.
Oh, and here's a link to the MDN entry for Object.create
, if you're interested: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/create/
You'll notice at the bottom that they actually include the polyfill, which is pretty much identical to your code, save for some safety checks and variable names.