Comparing version 0.0.1 to 0.0.2
90
index.js
@@ -26,67 +26,46 @@ /** | ||
//console.error('Setting Up: %s', ctor.name) | ||
if (ctor.create) { | ||
//console.error('create() already exists; bail') | ||
return ctor | ||
} | ||
switch (ctor.name) { | ||
case 'Function': | ||
setupFunction(ctor) | ||
break; | ||
case 'RegExp': | ||
setupRegexp(ctor) | ||
break; | ||
default: | ||
throw new Error('Constructor is unknown or unimplemented: ' + ctor.name) | ||
var m; | ||
try { | ||
m = require('./' + ctor.name.toLowerCase()) | ||
} catch (e) { | ||
throw new Error('Constructor is unknown or unimplemented: ' + ctor.name + '\n' + e) | ||
} | ||
return ctor | ||
} | ||
exports.setup = setup | ||
if (!ctor.create) { | ||
/** | ||
* Extends the Function constructor | ||
*/ | ||
function setupFunction (ctor) { | ||
function create () { | ||
var argv = arguments.length | ||
if (argv < 2) { | ||
throw new Error('Function.create() requires at least 2 arguments.') | ||
} | ||
var objectDescriptor = arguments[argv - 1] | ||
, instance = null | ||
, proto = null | ||
if (exports.isObjectDescriptor(objectDescriptor)) { | ||
proto = arguments[argv - 2] | ||
} else { | ||
proto = objectDescriptor | ||
objectDescriptor = null | ||
} | ||
var func = arguments[0] | ||
if (typeof func === 'function') { | ||
instance = function () { | ||
return func.apply(instance, arguments) | ||
function create () { | ||
var argc = arguments.length | ||
if (argc < 1) { | ||
throw new TypeError(ctor.name + ' prototype may only be an Object or null') | ||
} | ||
} else { | ||
throw new Error('TODO: invoke the constructor') | ||
var objectDescriptor = arguments[--argc] | ||
, instance = null | ||
, proto = null | ||
if (exports.isObjectDescriptor(objectDescriptor)) { | ||
proto = arguments[--argc] | ||
} else { | ||
proto = objectDescriptor | ||
objectDescriptor = null | ||
} | ||
var instance = m.newInstance(ctor, argc, arguments) | ||
// Set the instance's `prototype` | ||
instance.__proto__ = proto | ||
if (objectDescriptor) { | ||
// If an object descriptor was passed in, define those | ||
Object.defineProperties(instance, objectDescriptor) | ||
} | ||
return instance | ||
} | ||
instance.__proto__ = proto | ||
if (objectDescriptor) { | ||
Object.defineProperties(instance, objectDescriptor) | ||
} | ||
return instance | ||
ctor.create = create | ||
} | ||
ctor.create = create | ||
function isFunction (v) { | ||
return v instanceof ctor | ||
|| typeof v === 'function' | ||
|| Object.prototype.toString.call(v) == '[object Function]' | ||
var is = 'is' + ctor.name | ||
if (!ctor[is]) { | ||
//console.error('Setting up %s.%s()', ctor.name, is) | ||
ctor[is] = m.getIsFunc(ctor) | ||
} | ||
ctor.isFunction = isFunction | ||
return ctor | ||
} | ||
exports.setup = setup | ||
@@ -161,2 +140,3 @@ | ||
if (typeof o !== 'object') | ||
//if (typeof o !== 'object' || o === null) | ||
return false | ||
@@ -163,0 +143,0 @@ return 'value' in o |
{ "name": "create" | ||
, "description": "The missing Native.create() functions that ECMA forgot." | ||
, "keywords": [ "create", "ecma", "function", "subclass", "prototype", "array", "number" ] | ||
, "version": "0.0.1" | ||
, "version": "0.0.2" | ||
, "author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)" | ||
@@ -9,5 +9,5 @@ , "repository": { "type": "git", "url": "git://github.com/TooTallNate/create.git" } | ||
, "scripts": { | ||
"test": "for i in test/*.js; do node \"$i\"; done;" | ||
"test": "./test/run.sh" | ||
} | ||
, "engines": { "node": ">= 0.4.0 && < 0.7.0" } | ||
} |
@@ -5,3 +5,3 @@ create | ||
`create` is a module or node.js (and someday the browser too) that implements the | ||
`create` is a module for node.js (and someday the browser too) that implements the | ||
*"missing"* `.create()` functions on the rest of the native data types in | ||
@@ -70,2 +70,2 @@ JavaScript. | ||
From a browser standpoint, this module will only work in browsers where that is | ||
true (`__proto__` *MAY* be changed). In node this will work. | ||
true (`__proto__` *MAY* be changed). In node this will _always_ work. |
@@ -28,1 +28,4 @@ var create = require('../') | ||
assert.ok(!create.isObjectDescriptor(false3)) | ||
var false4 = false | ||
assert.ok(!create.isObjectDescriptor(false4)) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
14594
19
403
0
1
1