GithubHelp home page GithubHelp logo

power-object's Introduction

power-object

An object with superpowers!

Superpower report

  • Use objects as keys:
    const PowerObject = require('power-object');
    let obj = new PowerObject();
    
    // objects are always different
    let key1 = {};
    let key2 = {};
    let key3 = new Date(); // even classes (which are technically just objects)
    
    obj.set(key1, 400);
    obj.set(key2, 500);
    obj.set(key3, 'hi');
    obj.set(3, 'hello'); // numbers aren't stringified
    
    obj.get(key1); // 400
    obj.get(key2); // 500
    obj.get(key3); // 'hi'
    obj.get(3); // 'hello'
  • for...of iteration:
    const PowerObject = require('power-object');
    let obj = new PowerObject();
    
    let key1 = {};
    let key2 = {};
    
    obj.set(key1, 'some value');
    obj.set(key2, 89);
    
    for (let value of obj) console.log(value); // 'some value' then 89

Class docs

new PowerObject([object])

Returns a new PowerObject, optionally creating it from a given object. Unlike a regular object, you can't get or set a property directly (using obj[prop] or obj.prop).

PowerObject.prototype.get(key)

Retrieves a value from the PowerObject given a key. Unlike a regular Object, this can include Objects and doesn't stringify anything.

PowerObject.prototype.set(key, val)

Sets a value on the PowerObject for a given key. Unlike a regular Object, this can include Objects and doesn't stringify anything.

PowerObject.prototype.keys()

Returns an array containing the PowerObject's keys.

PowerObject.prototype.remove(key)

Removes a property from the PowerObject. Unlike a regular Object, this can include Objects and doesn't stringify anything.

PowerObject.prototype.clearAll()

Clears all properties from the PowerObject.

PowerObject.prototype[Symbol.iterator]

Returns an Iterator to iterate over the PowerObject's properties. Used by for...of to iterate.

power-object's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.