Comparing version 0.0.3 to 0.1.0
@@ -1,1 +0,1 @@ | ||
(typeof exports=="undefined"?this:exports).P=function(a,b,c,d){function e(a){return typeof a=="object"}function f(a){return typeof a=="function"}function g(a,g){function h(a){var b=this;if(b instanceof h)a&&f(b.init)&&b.init.apply(b,a);else return new h(arguments)}g===d?(g=a,a=Object):e(a[b])&&(h[b]=new a);var i=h[b],j=a[b],k={};i.constructor=h,f(g)?k=g.call(h,i,j,h,a):e(g)&&(k=g);if(e(k))for(var l in k)c.call(k,l)&&(i[l]=k[l]);return h}return g}([].slice,"prototype",{}.hasOwnProperty); | ||
var P=function(a,b,c,d){function e(a){return typeof a=="object"}function f(a){return typeof a=="function"}function g(a,g){function h(a){var b=this;if(b instanceof h)a&&f(b.init)&&b.init.apply(b,a);else return new h(arguments)}g===d&&(g=a,a=Object),h[b]=new a;var i=h[b],j=a[b],k={};i.constructor=h,f(g)?k=g.call(h,i,j,h,a):e(g)&&(k=g);if(e(k))for(var l in k)c.call(k,l)&&(i[l]=k[l]);return h}return g}([].slice,"prototype",{}.hasOwnProperty); |
@@ -1,2 +0,2 @@ | ||
exports.P = require('./src/p.js').P; | ||
exports.P = require('./build/p.commonjs').P; | ||
exports.version = JSON.parse(require('fs').readFileSync(__dirname + '/package.json')).version; |
{ | ||
"name": "pjs", | ||
"version": "0.0.3", | ||
"description": "A lightweight class system for the limbo artist", | ||
"version": "0.1.0", | ||
"description": "A lightweight class system. It's just prototypes!", | ||
"keywords": ["class", "pjs", "P", "inheritance", "super"], | ||
@@ -15,4 +15,5 @@ "author": "Jay Adkisson <jjmadkisson at gmail dot com>", | ||
"scripts": { | ||
"install": "make commonjs", | ||
"test": "make test" | ||
} | ||
} |
57
src/p.js
@@ -1,7 +0,38 @@ | ||
(typeof exports === 'undefined' ? this : exports) | ||
.P = (function(slice, prototype, hasOwnProperty, undefined) { | ||
var P = (function(slice, prototype, hasOwnProperty, undefined) { | ||
// helper functions that also help minification | ||
function isObject(o) { return typeof o === 'object'; } | ||
function isFunction(f) { return typeof f === 'function'; } | ||
function P(_superclass, definition) { | ||
function P(_superclass /* = Object */, definition) { | ||
// handle the case where no superclass is given | ||
if (definition === undefined) { | ||
definition = _superclass; | ||
_superclass = Object; | ||
} | ||
// C is the class to be returned. | ||
// There are three ways C will be called: | ||
// | ||
// 1) We call `new C` to create a new uninitialized object. | ||
// The behavior is similar to Object.create, where the prototype | ||
// relationship is set up, but the ::init method is not run. | ||
// Note that in this case we have `this instanceof C`, so we don't | ||
// spring the first trap. Also, `args` is undefined, so the initializer | ||
// doesn't get run. | ||
// | ||
// 2) A user will simply call C(a, b, c, ...) to create a new object with | ||
// initialization. This allows the user to create objects without `new`, | ||
// and in particular to initialize objects with variable arguments, which | ||
// is impossible with tne `new` keyword. Note that in this case, | ||
// !(this instanceof C) springs the return trap at the beginning, and | ||
// C is called with the `new` keyword and one argument, which is the | ||
// Arguments object passed in. | ||
// | ||
// 3) For internal use only, if new C(args) is called, where args is an | ||
// Arguments object. In this case, the presence of `new` means the | ||
// return trap is not sprung, but the initializer is called if present. | ||
// | ||
// TODO: the Chrome inspector shows all created objects as `C` rather than `Object`. | ||
// Setting the .name property seems to have no effect. Is there a way to override | ||
// this behavior? | ||
function C(args) { | ||
@@ -13,9 +44,6 @@ var self = this; | ||
if (definition === undefined) { | ||
definition = _superclass; | ||
_superclass = Object; | ||
} | ||
else if (isObject(_superclass[prototype])) { | ||
C[prototype] = new _superclass; | ||
} | ||
// set up the prototype of the new class | ||
// note that this resolves to `new Object` | ||
// if the superclass isn't given | ||
C[prototype] = new _superclass; | ||
@@ -27,11 +55,16 @@ var proto = C[prototype] | ||
// set the constructor property, for convenience | ||
proto.constructor = C; | ||
if (isFunction(definition)) { | ||
// call the defining function with all the arguments you need | ||
// extensions captures the return value. | ||
extensions = definition.call(C, proto, _super, C, _superclass); | ||
} | ||
else if (isObject(definition)) { | ||
// if you passed an object instead, we'll take it | ||
extensions = definition; | ||
} | ||
// ...and extend it | ||
if (isObject(extensions)) { | ||
@@ -48,3 +81,7 @@ for (var ext in extensions) { | ||
// ship it | ||
return P; | ||
// as a minifier optimization, we've closured in a few helper functions | ||
// and the string 'prototype' (C[p] is much shorter than C.prototype) | ||
})([].slice, 'prototype', ({}).hasOwnProperty); |
Sorry, the diff of this file is not supported yet
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
18479
17
345
1