Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clazzy

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clazzy - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

tests/Clazzy.js

54

Gruntfile.js

@@ -5,17 +5,12 @@ module.exports = function (grunt)

// --------------------------------------------------------------
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-uglify');
// Configuration
// --------------------------------------------------------------
grunt.initConfig(
{
package : grunt.file.readJSON('package.json'),
// ----------------------------------------------------------
jshint : // https://github.com/gruntjs/grunt-contrib-jshint
jshint :
{

@@ -26,7 +21,7 @@ options :

},
src : ['src/Clazzy.js', 'test/Clazzy.js']
src : ['src/Clazzy.js', 'tests/Clazzy.js']
},
nodeunit : // https://github.com/gruntjs/grunt-contrib-nodeunit
nodeunit :
{

@@ -38,30 +33,9 @@ options :

all : ['test/Clazzy.js']
},
uglify : // https://github.com/gruntjs/grunt-contrib-uglify
{
build :
{
files :
{
'build/Clazzy.js' : 'src/Clazzy.js'
}
},
options :
{
banner : '// Clazzy \n'
+ '// Version: <%= package.version %> \n'
+ '// Author: <%= package.author.name %> (<%= package.author.url %>) \n'
+ '// License: <%= package.license %> \n',
report : 'gzip'
}
all : ['tests/Clazzy.js']
}
});
// Task: `test`
// --------------------------------------------------------------
grunt.registerTask('test', ['jshint', 'nodeunit']);

@@ -71,9 +45,9 @@

// --------------------------------------------------------------
grunt.registerTask('build', ['test', 'uglify']);
grunt.registerTask('build', ['test']);
// Task: `default`
// --------------------------------------------------------------
grunt.registerTask('default', ['build']);
};
};
MIT License
Copyright (c) 2014 Luke Phillips
Copyright (c) 2014 - 2016 Luke Phillips

@@ -9,8 +9,8 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
{
"name" : "clazzy",
"version" : "0.1.2",
"version" : "0.2.0",

@@ -11,5 +11,3 @@ "description" : "A cross platform JavaScript library that provides a classical interface to prototypal inheritance.",

"name" : "Luke Phillips",
"email" : "lukephil92@gmail.com",
"email" : "lsphillips.mail@gmail.com",
"url" : "http://lsphillips.com"

@@ -25,3 +23,3 @@ },

"include",
"trait",
"trait",
"mixin"

@@ -37,21 +35,9 @@ ],

"directories" :
{
"src" : "src",
"test" : "test"
},
"devDependencies" :
{
"grunt" : "^0.4.5",
"grunt-contrib-jshint" : "^0.10.0",
"grunt-contrib-uglify" : "^0.5.1",
"grunt-contrib-nodeunit" : "^0.4.1"
"grunt" : "0.4.5",
"grunt-contrib-jshint" : "0.11.3",
"grunt-contrib-nodeunit" : "0.4.1"
},
"scripts" :
{
"test" : "grunt test"
},
"main" : "src/Clazzy.js",

@@ -66,2 +52,2 @@

"license" : "MIT"
}
}

@@ -1,5 +0,7 @@

## Clazzy
# Clazzy
A cross platform JavaScript library that provides a classical interface to prototypal inheritance.
**This project is now deprecated in favor of the ECMAScript 6 class syntax, this project will no longer be maintained. Sorry!**
## Usage

@@ -13,3 +15,2 @@

// Constructor
// --------------------------------

@@ -22,3 +23,2 @@ initialize : function ()

// Instance methods
// --------------------------------

@@ -34,7 +34,6 @@ bar : function ()

},
// Static methods
// --------------------------------
static :
static :
{

@@ -54,3 +53,3 @@ qux : function ()

foo.baz('baz'); // 'baz'
foo.baz('baz'); // 'baz'

@@ -60,3 +59,3 @@ Foo.qux(); // 'qux'

*Note:* Instance properties can be defined in the definition, however their inital value should be set in the constructor.
**Note:** Instance properties can be defined in the definition, however their inital value should be set in the constructor.

@@ -70,8 +69,5 @@ ### Creating a class that extends another class

// --------------------------------
initialize : function ()
{
this.super();
// -------------

@@ -81,4 +77,2 @@ this.corge = 'corge';

// --------------------------------
baz : function ()

@@ -108,3 +102,3 @@ {

*Note:*
**Note:**

@@ -123,4 +117,2 @@ * Static methods are not inherited.

// --------------------------------
moo : function ()

@@ -145,3 +137,3 @@ {

*Note:*
**Note:**

@@ -154,6 +146,4 @@ * Static methods are not included.

### Node
Clazzy is available through the Node Package Manager (NPM), so you can install it like so:
Clazzy is available through the Node Package Manager, so you can install like so:
``` sh

@@ -163,25 +153,5 @@ npm install clazzy

and bring into your code like so:
``` js
var Clazzy = require('clazzy');
```
### Browser
To use Clazzy in a browser envrionment, just use a script tag like so:
``` html
<script type="text/javascript" src="path/to/Clazzy.js"></script>
```
To remove Clazzy from the global namespace, you can use `Clazzy.noConflict()`, like so:
``` js
Namespace.Clazzy = Clazzy.noConflict();
```
## Development
Grunt is used to handle the build process for Clazzy. To perform a full build, use the `build` task:
Grunt is used to handle the build process for this project. To perform a full build, use the `build` task:

@@ -192,16 +162,12 @@ ``` sh

which is just an alias for the `default` task:
To only run tests use the `test` task:
``` sh
grunt
grunt test
```
To only check code quality and/or run unit tests use the `test` task:
This also runs code quality checks using JSHint. Please refer to the `.jshintrc` file to familiar yourself with the rules.
``` sh
grunt test
```
## License
Clazzy is released under the MIT License.
This project is released under the MIT License.

@@ -1,342 +0,291 @@

(function (name, factory, context)
'use strict';
// We need to pass array-like objects, such as the arguments
// object, to `Function#apply`, however not all implementations yet
// allow array-like objects to be passed to it. So we need to
// convert them to an array, this can be done using `Array#slice`.
//
// A further problem, is you can't slice array-like objects
// directly, like so:
//
// arguments.slice(0);
//
// As they aren't arrays, however the method will still work if
// applied like this:
//
// Array.prototype.slice.call(arguments, 0);
var slice = Array.prototype.slice;
// Keywords
// ------------------------------------------------------------------
var SUPER = 'super';
var INITIALIZE = 'initialize';
var EXTEND = 'extend';
var STATIC = 'static';
var INCLUDE = 'include';
var FUNCTION = 'function';
var CONSTRUCTOR = 'constructor';
// Helpers
// ------------------------------------------------------------------
var createAnUnconstructedInstanceOfClass = (function ()
{
if (typeof module !== 'undefined' && module.exports)
if (Object.create === undefined)
{
module.exports = factory.call(context);
return function (clazz)
{
function Surrogate ()
{
// A surrogate function that does nothing. It
// will allow us to create an object of a
// prototype without running it's constructor.
}
Surrogate.prototype = clazz.prototype;
Surrogate.prototype[CONSTRUCTOR] = clazz;
return new Surrogate();
};
}
else if (typeof define === 'function' && define.amd)
return function (clazz)
{
define(name, [], factory);
}
else
return Object.create(clazz.prototype);
};
}) ();
var getPropertyDescriptor = function (object, property, deep)
{
var descriptor = Object.getOwnPropertyDescriptor(object, property);
if (descriptor !== undefined)
{
context[name] = factory.call(context);
return descriptor;
}
}) ('Clazzy', function ()
{
'use strict';
// We need to pass array-like objects, such as the arguments
// object, to `Function#apply`, however not all implementations yet
// allow array-like objects to be passed to it. So we need to
// convert them to an array, this can be done using `Array#slice`.
//
// A further problem, is you can't slice array-like objects
// directly, like so:
//
// arguments.slice(0);
//
// As they aren't arrays, however the method will still work if
// applied like this:
//
// Array.prototype.slice.call(arguments, 0);
var slice = Array.prototype.slice;
// The `Object.hasOwnProperty` method is not protected, which
// allows an object to override it, making using the method
// like this:
//
// object.hasOwnProperty('property');
//
// Very unreliable, so we need to do this instead:
//
// Object.prototype.hasOwnProperty(object, 'property');
var hasOwnProperty = Object.prototype.hasOwnProperty;
if (deep)
{
var prototype = object;
// Keywords
// --------------------------------------------------------------
var SUPER = 'super';
var INITIALIZE = 'initialize';
var EXTEND = 'extend';
var STATIC = 'static';
var INCLUDE = 'include';
var FUNCTION = 'function';
var CONSTRUCTOR = 'constructor';
// Helpers
// --------------------------------------------------------------
var createAnUnconstructedInstanceOfClass = (function ()
{
if (Object.create === undefined)
do
{
return function (clazz)
{
function Surrogate ()
{
// A surrogate function that does nothing. It
// will allow us to create an object of a
// prototype without running it's constructor.
}
Surrogate.prototype = clazz.prototype;
Surrogate.prototype[CONSTRUCTOR] = clazz;
return new Surrogate();
};
prototype = Object.getPrototypeOf(prototype);
// Climb down the next kink of the prototype chain and
// attempt to retrieve the property descriptor from
// that kink.
descriptor = Object.getOwnPropertyDescriptor(prototype, property);
}
return function (clazz)
{
return Object.create(clazz.prototype);
};
while (prototype !== undefined && descriptor === undefined);
}
}) ();
return descriptor;
};
var copyProperty = (function ()
var copyProperty = (function ()
{
// IE8 implements `Object.defineProperty`, however it only
// works on DOM elements. So IE8 must also use a fall-back
// method, requiring us to check for the implementation of
// `Object.defineProperties` instead.
if (Object.defineProperties === undefined)
{
// IE8 implements `Object.defineProperty`, however it only
// works on DOM elements. So IE8 must also use a fall-back
// method, requiring us to check for the implementation of
// `Object.defineProperties` instead.
if (Object.defineProperties === undefined)
return function (source, target, property)
{
return function (source, target, property)
{
target[property] = source[property];
};
}
return function (source, target, property, deep)
{
var descriptor = getPropertyDescriptor(source, property, deep);
if (descriptor !== undefined)
{
// Normally this would suffice:
//
// target[property] = methods[property];
//
// However for ECMA5 getters, this wouldn't work, as it
// would be invoked, assigning the value being
// returned by the getter, rather than it's definition.
Object.defineProperty(target, property, descriptor);
}
target[property] = source[property];
};
}) ();
}
var copyProperties = function (source, target, deep)
return function (source, target, property, deep)
{
for (var property in source)
var descriptor = getPropertyDescriptor(source, property, deep);
if (descriptor !== undefined)
{
if ( deep || hasOwnProperty.call(source, property) )
{
copyProperty(source, target, property, deep);
}
// Normally this would suffice:
//
// target[property] = methods[property];
//
// However for ECMA5 getters, this wouldn't work, as it
// would be invoked, assigning the value being
// returned by the getter, rather than it's definition.
Object.defineProperty(target, property, descriptor);
}
};
var getPropertyDescriptor = function (object, property, deep)
}) ();
var copyProperties = function (source, target, deep)
{
for (var property in source)
{
var descriptor = Object.getOwnPropertyDescriptor(object, property);
if (descriptor !== undefined)
if ( deep || hasOwnProperty.call(source, property) )
{
return descriptor;
copyProperty(source, target, property, deep);
}
if (deep)
}
};
// ------------------------------------------------------------------
var wrap = (function ()
{
function noSuper ()
{
throw new Error('Cannot call super, this method does not override a parent method');
}
return function (method, signature, base)
{
return function ()
{
var prototype = object;
do
var tmp = this[SUPER];
this[SUPER] = base.prototype[signature] || noSuper;
var result;
try // to execute the method.
{
prototype = Object.getPrototypeOf(prototype);
// Climb down the next kink of the prototype chain and
// attempt to retrieve the property descriptor from
// that kink.
descriptor = Object.getOwnPropertyDescriptor(prototype, property);
result = method.apply(
this, slice.call(arguments)
);
}
while (prototype !== undefined && descriptor === undefined);
}
return descriptor;
finally
{
this[SUPER] = tmp;
}
return result;
};
};
// --------------------------------------------------------------
var wrap = (function ()
}) ();
// ------------------------------------------------------------------
module.exports =
{
create : function (definition)
{
function noSuper ()
if (definition === undefined)
{
throw new Error('[Clazzy] Cannot call super, this method does not override a parent method');
definition = {};
}
return function (method, signature, base)
{
return function ()
{
var tmp = this[SUPER];
this[SUPER] = base.prototype[signature] || noSuper;
var result;
try // to execute the method.
{
result = method.apply(
this, slice.call(arguments)
);
}
finally
{
this[SUPER] = tmp;
}
return result;
};
};
}) ();
var initialize, base, includes;
// --------------------------------------------------------------
// 1) Constructor
var Clazzy =
{
create : function (definition)
function Class ()
{
if (definition === undefined)
if (includes !== undefined)
{
definition = {};
}
var initialize, base, includes;
// Constructor
// ------------------------------------------------------
function Class ()
{
if (includes !== undefined)
for (var i = 0, l = includes.length; i < l; ++i)
{
for (var i = 0, l = includes.length; i < l; ++i)
{
includes[i].call(this);
}
includes[i].call(this);
}
if (initialize !== undefined)
{
initialize.apply(
this, slice.call(arguments)
);
}
}
// Extend
// ------------------------------------------------------
base = definition[EXTEND];
if (base === undefined)
if (initialize !== undefined)
{
base = Object;
initialize.apply(
this, slice.call(arguments)
);
}
else
}
// 2) Inherit
base = definition[EXTEND];
if (base === undefined)
{
base = Object;
}
else
{
Class.prototype = createAnUnconstructedInstanceOfClass(base);
// Default the class initializer to the base class
// constructor.
initialize = base.prototype.constructor;
}
// 3) Mixin
includes = definition[INCLUDE];
if (includes !== undefined)
{
for (var i = 0, l = includes.length; i < l; ++i)
{
Class.prototype = createAnUnconstructedInstanceOfClass(base);
// Default the class initializer to the base class
// constructor.
initialize = base.prototype.constructor;
var include = createAnUnconstructedInstanceOfClass(
includes[i]
);
copyProperties(include, Class.prototype, true);
}
// Include
// ------------------------------------------------------
includes = definition[INCLUDE];
if (includes !== undefined)
}
// 4) Define
for (var property in definition)
{
if ( hasOwnProperty.call(definition, property) )
{
for (var i = 0, l = includes.length; i < l; ++i)
var member = definition[property];
switch (property)
{
var include = createAnUnconstructedInstanceOfClass(
includes[i]
);
copyProperties(include, Class.prototype, true);
}
}
// Methods
// ------------------------------------------------------
for (var property in definition)
{
if ( hasOwnProperty.call(definition, property) )
{
var member = definition[property];
switch (property)
{
case INITIALIZE :
initialize = wrap(member, CONSTRUCTOR, base);
break;
case EXTEND :
case INCLUDE :
// We have already dealt with these
// properties.
break;
case STATIC :
copyProperties(member, Class, false);
break;
case INITIALIZE :
case SUPER :
initialize = wrap(member, CONSTRUCTOR, base);
throw new Error('[Clazzy] Cannot create class, `super` is a reserved method name');
default :
if (typeof member === FUNCTION)
{
// Always wrap the method, even if a
// parent method doesn't exist at the
// moment, as a method could later be
// injected into the prototye.
Class.prototype[property] = wrap(member, property, base);
}
else
{
copyProperty(definition, Class.prototype, property);
}
}
break;
case EXTEND :
case INCLUDE :
// We have already dealt with these
// properties.
break;
case STATIC :
copyProperties(member, Class, false);
break;
case SUPER :
throw new Error('Cannot create class, `super` is a reserved method name.');
default :
if (typeof member === FUNCTION)
{
// Always wrap the method, even if a
// parent method doesn't exist at the
// moment, as a method could later be
// injected into the prototye.
Class.prototype[property] = wrap(member, property, base);
}
else
{
copyProperty(definition, Class.prototype, property);
}
}
}
Class.prototype[CONSTRUCTOR] = Class;
return Class;
},
}
noConflict : (function (context)
{
var _Clazzy = context.Clazzy;
return function ()
{
context.Clazzy = _Clazzy;
return this;
};
Class.prototype[CONSTRUCTOR] = Class;
}) (this)
};
// --------------------------------------------------------------
return Clazzy;
}, this);
return Class;
}
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc