Git Product home page Git Product logo

Comments (8)

ikokostya avatar ikokostya commented on June 6, 2024
  • We use simple rule for all conversions
  • Don't use new with Boolean

from mapsapi-codestyle.

twirl avatar twirl commented on June 6, 2024

We use simple rule for all conversions

That's senseless. Your rule leeds to errors.

Don't use new with Boolean

I never do that. But imagine that your code is API, and third-party developers pass values to it. And - surprise! - they have style guide of their own.

from mapsapi-codestyle.

ikokostya avatar ikokostya commented on June 6, 2024

and third-party developers pass values to it

All our code based on contract between developer and third-party developer. If third-party developer violates contract this is his fault.

In your example Boolean and !! have same result:

> var b = new Boolean(false);
undefined
> b
false
> Boolean(b)
true
> !!b
true

from mapsapi-codestyle.

twirl avatar twirl commented on June 6, 2024

Okay, new Boolean(false) was a bad example. Take any other ‘truthy’ value, like [].
Please, explain the logic to me: you allow third-party to provide values of any type instead of Boolean, but your internal cast is not the same as browser default. How should third-party know that?

from mapsapi-codestyle.

dmikis avatar dmikis commented on June 6, 2024

We use type conversion only when we want to explicitly convert a value to the boolean type (or a string or a number for that matter). In other words, only when we going to encapsulate some logic behind obtaining the value in question. For example:

SomeClassWithArrayWithin.prototype.isEmpty = function () {
    return Boolean(this._array.length);
};

Here we deliberately lose information about the array within the implementation and, of course, about its length.

In other cases we just rely upon type coercion.

from mapsapi-codestyle.

ikokostya avatar ikokostya commented on June 6, 2024

Take any other ‘truthy’ value, like [].
Please, explain the logic to me: you allow third-party to provide values of any type instead of Boolean, but your internal cast is not the same as browser default.

I don't understand problem with Boolean:

> var a = []
undefined
> Boolean(a)
true
> !!a
true

but your internal cast is not the same as browser default

What do you mean? Provide examples please.

from mapsapi-codestyle.

twirl avatar twirl commented on June 6, 2024

We use type conversion only when we want to explicitly convert a value to the boolean type (or a string or a number for that matter)

Does it mean that you are using expressions like that?

if (Boolean(arr.length) === false) {
    // ...
}

And what are you doing with polymorphic functions?

from mapsapi-codestyle.

twirl avatar twirl commented on June 6, 2024

Issue is closed, in Harmony this issue resolved.
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-toboolean

from mapsapi-codestyle.

Related Issues (20)

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.