mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Make sure the Base class is exposed in Node.js
This commit is contained in:
parent
45ab6c7676
commit
c70b985911
3 changed files with 5 additions and 9 deletions
|
@ -18,7 +18,7 @@
|
|||
* http://dev.helma.org/Wiki/JavaScript+Inheritance+Sugar/
|
||||
*/
|
||||
|
||||
var Base = new function() { // Bootstrap scope
|
||||
var Base = this.Base = new function() { // Straps scope
|
||||
var hidden = /^(statics|generics|preserve|enumerable|prototype|toString|valueOf)$/,
|
||||
proto = Object.prototype,
|
||||
toString = proto.toString,
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
// When in dev mode, also export all classes through PaperScope, to mimick
|
||||
// scoping behavior of the built library.
|
||||
Base.each(this, function(val, key) {
|
||||
if (val && val.prototype instanceof Base)
|
||||
if (val && val.prototype instanceof Base || val === Base)
|
||||
PaperScope.prototype[key] = val;
|
||||
});
|
||||
// See paper.js for the non-dev version of this code. We cannot handle dev there
|
||||
|
|
|
@ -93,8 +93,6 @@ context.include('paper.js');
|
|||
// to redefine Base.isPlainObject() here.
|
||||
// So instead of checking for Object.prototype, we're checking
|
||||
// proto.constructor.name for 'Object'
|
||||
// TODO: Benchmark the speed and consider this implementation instead of the
|
||||
// current one in straps.js too
|
||||
var Base = context.Base;
|
||||
Base.isPlainObject = function(obj) {
|
||||
var proto = obj !== null && typeof obj === 'object'
|
||||
|
@ -103,16 +101,14 @@ Base.isPlainObject = function(obj) {
|
|||
|| proto === Base.prototype);
|
||||
};
|
||||
|
||||
// Expose the Canvas, XMLSerializer to paper scopes:
|
||||
Base.each({
|
||||
context.PaperScope.inject({
|
||||
// Expose the Canvas, XMLSerializer & DOMParser to PaperScope:
|
||||
Canvas: Canvas,
|
||||
XMLSerializer: XMLSerializer,
|
||||
DOMParser: DOMParser,
|
||||
// Also fix version. Remove 2nd dot, so we can make a float out of it:
|
||||
version: parseFloat(json.version.replace(/(.)(\d)$/, '$2'))
|
||||
}, function(value, key) {
|
||||
this[key] = value;
|
||||
}, context.PaperScope.prototype);
|
||||
});
|
||||
|
||||
require.extensions['.pjs'] = function(module, uri) {
|
||||
var source = context.PaperScript.compile(fs.readFileSync(uri, 'utf8'));
|
||||
|
|
Loading…
Reference in a new issue