Giter Site home page Giter Site logo

mb's Introduction

mb

goat

Exception-free nested nullable attribute accessor. An alternative to facebookincubator/idx in 38 bytes.


Install

Just copy/paste this function into your project:

var mb=p=>o=>p.map(c=>o=(o||{})[c])&&o

Alternatively, you can download mb.js.

Use

var getHello = mb(["a", "b", 0, "hello"]);
var getHelloLength = mb(["a", "b", 0, "hello", "length"]);

var obj1 = {
  a: {
    b: [{ hello: "world" }]
  }
};

var obj2 = {
  c: {
    d: "e"
  }
};

getHello(obj1); // world
getHelloLength(obj1); // 5

getHello(obj2); // undefined
getHelloLength(obj2); // undefined

Contribution and Code-Golfing

  1. Clone and shorten current code.
  2. Please open test.html in your browser and open console to see if all the tests pass.

Contributors

mb's People

Contributors

aborjinik avatar alpert avatar atmin avatar burakcan avatar cekici avatar eser avatar f avatar maxwellgerber avatar peterlevi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mb's Issues

Explanation of how this works ?

Hi,

Just discovered the library and was wondering if you could provide an explanation for those of us who are lost by the syntax ? It's always great to learn something new about javascript 😄

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.