Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created June 15, 2011 09:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Gozala/d33befccbe1e0ed492d5 to your computer and use it in GitHub Desktop.
Save Gozala/d33befccbe1e0ed492d5 to your computer and use it in GitHub Desktop.
Pure prototypial inheritance in JS.
const SkinnedMesh = THREE.Mesh.extend({
new: function SkinnedMesh(geometry, materials) {
var self = THREE.Mesh.new.apply(SkinnedMesh, arguments);
// initialize instance properties
self.identityMatrix = THREE.Matrix4.new();
self.bones = [];
self.boneMatrices = [];
return self;
},
update: function(camera) {
...
// call base version of same method
THREE.Mesh.update.call(this);
}
});
/* vim:set ts=2 sw=2 sts=2 expandtab */
/*jshint undef: true es5: true node: true devel: true evil: true
forin: true latedef: false supernew: true */
/*global define: true */
"use strict";
Object.prototype.new = function new() {
return new this.constructor();
};
Object.prototype.extend = function extend(properties) {
var constructor = new Function(), descriptor = {};
properties = properties || {};
Object.getOwnPropertyNames(properties).forEach(function(name) {
descriptor[name] = Object.getOwnPropertyDescriptor(properties, name);
});
descriptor.constructor = { value: constructor };
return Object.freeze(constructor.prototype = Object.create(this, descriptor));
};
Object.new = function new() {
return Object.prototype.new();
};
Object.extend = function extend(properties) {
return Object.prototype.extend(properties);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment