This is a standalone implementation of ES5's Object.create:
window.createObject = (function() {
var F = function () {};
return function(o) {
F.prototype = o;
return new F();
}
}());
and an example of its use:
var cat = createObject(animal);
I've noticed the internals of animal
are getting a little messy when trying to call private functions, e.g.:
animal = (function() {
function privFunc(arg) {
this.property;
}
function publFunc(arg) {
privFunc.call(this, arg);
}
return {
publFunc: publFunc
}
}());
Is there a cleaner way to follow this type of pattern? In particular, removing the need for privFunc.call(this, arg)
.
Another way, equally as ugly is:
function privFunc(animal, arg) {
animal.property;
}
function publFunc(arg) {
privFunc(this, arg);
}