core-object
Advanced tools
Comparing version 2.0.6 to 2.1.0
'use strict'; | ||
var assignProperties = require('./lib/assign-properties'); | ||
var deprecation = require('./lib/deprecation'); | ||
const assignProperties = require('./lib/assign-properties'); | ||
const deprecation = require('./lib/deprecation'); | ||
function needsNew() { | ||
throw new TypeError("Failed to construct: Please use the 'new' operator, this object constructor cannot be called as a function."); | ||
} | ||
function CoreObject(options) { | ||
if (!(this instanceof CoreObject)) { | ||
needsNew() | ||
class CoreObject { | ||
constructor() { | ||
this.init.apply(this, arguments); | ||
} | ||
this.init(options); | ||
} | ||
CoreObject.prototype.init = function(options) { | ||
if (options) { | ||
for (var key in options) { | ||
this[key] = options[key]; | ||
init(options) { | ||
if (options) { | ||
for (let key in options) { | ||
this[key] = options[key]; | ||
} | ||
} | ||
} | ||
}; | ||
CoreObject.extend = function(options) { | ||
var constructor = this; | ||
static extend(options) { | ||
class Class extends this { } | ||
function Class() { | ||
var length = arguments.length; | ||
if (options) { | ||
if (shouldCallSuper(options.init)) { | ||
if (length === 0) this.init(); | ||
else if (length === 1) this.init(arguments[0]); | ||
else this.init.apply(this, arguments); | ||
} | ||
Class.__proto__ = CoreObject; | ||
Class.prototype = Object.create(constructor.prototype); | ||
if (options) { | ||
if (shouldCallSuper(options.init)) { | ||
if (hasArgs(options.init)) { | ||
deprecation( | ||
'Overriding init without calling this._super is deprecated. ' + | ||
if (hasArgs(options.init)) { | ||
deprecation( | ||
'Overriding init without calling this._super is deprecated. ' + | ||
'Please call this._super(), addon: `' + options.name + '`' | ||
); | ||
options.init = forceSuperWithoutApply(options.init); | ||
} else { | ||
); | ||
options.init = forceSuperWithoutApply(options.init); | ||
} else { | ||
// this._super.init && is to make sure that the deprecation message | ||
// works for people who are writing addons supporting before 2.6. | ||
deprecation( | ||
'Overriding init without calling this._super is deprecated. ' + | ||
// this._super.init && is to make sure that the deprecation message | ||
// works for people who are writing addons supporting before 2.6. | ||
deprecation( | ||
'Overriding init without calling this._super is deprecated. ' + | ||
'Please call `this._super.init && this._super.init.apply(this, arguments);` addon: `' + options.name + '`' | ||
); | ||
options.init = forceSuper(options.init); | ||
); | ||
options.init = forceSuper(options.init); | ||
} | ||
} | ||
assignProperties(Class.prototype, options); | ||
} | ||
assignProperties(Class.prototype, options); | ||
return Class; | ||
} | ||
} | ||
return Class; | ||
}; | ||
function hasArgs(fn) { | ||
@@ -67,0 +50,0 @@ // Takes arguments, assume disruptive override |
@@ -1,3 +0,5 @@ | ||
var deprecation = require('./deprecation'); | ||
'use strict'; | ||
const deprecation = require('./deprecation'); | ||
function setPrototypeOf(obj, proto) { | ||
@@ -13,3 +15,3 @@ Object.setPrototypeOf ? Object.setPrototypeOf(obj, proto) : obj.__proto__ = proto; | ||
return function superWrapper() { | ||
var superFn; | ||
let superFn; | ||
@@ -31,5 +33,5 @@ if (superclass[name]) { | ||
var previous = this._super; | ||
const previous = this._super; | ||
this._super = superFn; | ||
var ret = fn.apply(this, arguments); | ||
const ret = fn.apply(this, arguments); | ||
this._super = previous; | ||
@@ -40,7 +42,7 @@ return ret; | ||
var sourceAvailable = (function() { | ||
const sourceAvailable = (function() { | ||
return this; | ||
}).toString().indexOf('return this') > -1; | ||
var hasSuper; | ||
let hasSuper; | ||
if (sourceAvailable) { | ||
@@ -60,6 +62,6 @@ hasSuper = function(fn) { | ||
function assignProperties(target, options) { | ||
var value; | ||
module.exports = function assignProperties(target, options) { | ||
let value; | ||
for (var key in options) { | ||
for (let key in options) { | ||
value = options[key]; | ||
@@ -73,4 +75,2 @@ | ||
} | ||
} | ||
module.exports = assignProperties; | ||
}; |
'use strict'; | ||
var env = require('./env'); | ||
var chalk = require('chalk'); | ||
const env = require('./env'); | ||
module.exports = function deprecation(msg) { | ||
var error = new Error(); | ||
var stack = error.stack.split(/\n/); | ||
var source = stack[3]; | ||
let error = new Error(); | ||
let stack = error.stack.split(/\n/); | ||
let source = stack[3]; | ||
console.warn(chalk.yellow('DEPRECATION: ' + msg + '\n' + source)); | ||
console.warn(require('chalk').yellow('DEPRECATION: ' + msg + '\n' + source)); | ||
}; |
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
module.exports = ( | ||
@@ -2,0 +4,0 @@ (typeof window !== 'undefined' && window) || |
{ | ||
"name": "core-object", | ||
"version": "2.0.6", | ||
"version": "2.1.0", | ||
"description": "A lightweight implementation of OOP Class in JavaScript", | ||
@@ -32,3 +32,2 @@ "main": "core-object.js", | ||
"klass": "^1.4.0", | ||
"microtime": "^2.1.1", | ||
"mocha": "^3.0.0", | ||
@@ -35,0 +34,0 @@ "traceur-runtime": "0.0.59", |
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
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
7
5699
140
1