npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clonejs

v1.3.2-alpha

Published

The true prototype-based JavaScript micro-framework.

Downloads

3

Readme

clone.js Build Status

[ API documentation | GitHub | NPM package | Travis CI ]

This is the micro-framework that based on the ECMA Script 5 features like Object.create⠙ and property descriptors⠙.

Try the true prototype-based OOP⠙

It's trivial to create new "classes" - just clone the prototype and change a couple of properties and voila... new "class".

It's really class-free: do you know the difference between js constructor-functions and classes in other languages? $object.clone produces prototype objects, not function-constructors, unlike other class-producing tools (Backbone.Model.extend, Ext.define, dojo.declare).

In this framework you can easilly create and manipulate objects without constructors, instead of js way, where you should define a constructor for every object (that you want to use as prototype), even if you didn't need it. It's possible to build and maintain extremely large numbers of "classes" with comparatively little code.

See more advantages of prototype-based OOP⠙.

Installation

Node.js:

npm install clonejs

CDN⠙ for client-side (~3 KB gzipped):

<script src="http://quadroid.github.com/clonejs/cdn/clone.min.js" type="text/javascript"></script>

Usage

Node.js:

var ns = require('clonejs'),
    $object = ns.prototype;
Quick example (cloning):
var $myProto = {a:1, b:2, c:3};
var    clone = $object.clone.apply($myProto);
     clone.a = 11; // $myProto.a still == 1
  $myProto.b = 22; // clone.b will be also changed to 22

See: clone, create, copy, deepCopy, deepClone.

Property modificators:
var $myType = $object.clone({
    '(final)          property1': "not configurable and not writable",
    '(writable final) property2': "not configurable only",
    '(hidden)         property3': "not enumerable",
    '(const)           constant': "not writable",
                      property4 : "simple property",
    '(get)       property3alias': 'property3',// automatically create getter
                          _item : "private property (not enumerable)",
                   '(get)  item': function() { return this._item },
                   '(set)  item': function(v){ this._item = v    },
                    constructor : 'MyType'
});
assert( $myType.property3alias === $myType.property3 );

See: describe.

Constructors & instantiation:
var $parent = $object.clone({
    constructor: function Parent(){
        console.log('$parent constructor arguments:', arguments);
    }
});
var $child = $parent.clone({
    constructor: function Child(arg){
        console.log('$child constructor arguments:', arguments);
        this.callSuper('constructor', arg);
    }
});
var $grandchild = $child.clone({
    constructor: function Grandchild(){
        console.log('$grandchild constructor arguments:', arguments);
        this.applySuper(arguments);
    }
});
var grandchild = $grandchild.create(1,2,3);
    // will output:
    // $grandchild constructor arguments: [1,2,3]
    // $child constructor arguments: [1,2,3]
    // $parent constructor arguments: [1]
    
assert( $child.isPrototypeOf(grandchild) );

See: constructor, create, applySuper, callSuper, createSuperSafeCallback.

Properties iteration:
var $obj = $object.clone({a: 11, b: 22, c: 33}),
     obj = $obj.create({d: 44});

var mappedObj = obj.map(function(value){return 100 + value}, obj, true);
    // mappedObj == {d: 144} // mapped only own property

var proto = {e: 55};
mappedObj = obj.map(function(value){return 100 + value}, obj, false, proto);
    // mappedObj == {a: 111, b: 122, c: 133, d: 144, e: 155}
proto.f = 66;
    // mappedObj == {a: 111, b: 122, c: 133, d: 144, e: 155, f: 66}

See: forEach, map, filter, every, some.

Namespaces:
ns.extend('collection', {
    $item:  {},
    _items: {}
});
ns.collection.extend('arrayCollection', {_items: []});

var $users = ns.collection.$arrayCollection.clone({
    $item: {name: '', isAdmin: false},
    constructor: function Users(items){
        items.forEach(function(item){
            var newItem = $object.create.call(this.$item, item);
            this._items.push(newItem);
        }, this);
    }
});
ns.put('models.users', $users);

var users = ns.models.$users.create([{name: 'User1'}]);

See: ns, ns.extend, ns.put.

yandex metrika githalytics.com alpha