Permalink
Browse files

Move the class_compat.js experiment to a gist.

  • Loading branch information...
1 parent 7f4e660 commit 33267cc1274b21929f625466f64c9cd6451315fa @creationix committed Aug 19, 2010
Showing with 0 additions and 31 deletions.
  1. +0 −31 lib/class_compat.js
View
@@ -1,31 +0,0 @@
-var Class = require('./class');
-
-// This global modifier allows you to treat constructor based classes as if
-// they were prototype based.
-
-// Define an extend method for constructor functions that works like prototype extends.
-Object.defineProperty(Function.prototype, "extend", {value: function extend(obj) {
- // Clone the functions's prototype
- var props = {}, proto = this.prototype;
- Object.getOwnPropertyNames(proto).forEach(function (key) {
- props[key] = Object.getOwnPropertyDescriptor(proto, key);
- });
-
- // Put the constructor on a prop too
- props.constructor = {value: this};
-
- // Make obj's parent be an Classy version of props
- if (obj === undefined) return Object.create(Class, props);
- obj.__proto__ = Object.create(Class, props);
- Object.freeze(obj);
- return obj;
-}});
-
-// This is the "new" keyword implemented in pure ES5
-// I added sealing on top of what "new" does
-Object.defineProperty(Function.prototype, "new", {value: function () {
- var obj = Object.create(this.prototype, {constructor: this});
- var result = this.apply(obj, arguments);
- Object.seal(obj);
- return result === undefined ? obj : result;
-}});

0 comments on commit 33267cc

Please sign in to comment.