-
-
Save Gozala/d33befccbe1e0ed492d5 to your computer and use it in GitHub Desktop.
Pure prototypial inheritance in JS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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