Comments (8)
- We use simple rule for all conversions
- Don't use
new
with Boolean
from mapsapi-codestyle.
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.
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.
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.
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.
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.
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.
Issue is closed, in Harmony this issue resolved.
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-toboolean
from mapsapi-codestyle.
Related Issues (20)
- async without await HOT 1
- Use tslint "max-line-length" rule HOT 1
- Обязательный вызов конструктора родителя в конструкторе дочернего класса HOT 1
- Codestyle for ES6 HOT 3
- Enums code style HOT 12
- Spaces around comma HOT 3
- Required space in class methods names HOT 6
- JSCS 3 support for loris preset HOT 2
- Update eslint rules HOT 3
- Clarifying object notation HOT 2
- Class properties order HOT 5
- Type assertions style
- Move react preset to separate package
- Add tslint config
- Add rule for beginning underscore for private fields HOT 1
- Mandatory return type for functions and methods HOT 3
- Identifier references in object literals HOT 7
- Template parameter naming HOT 9
- Add rule for spaces in imports HOT 2
- Ternary operator HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mapsapi-codestyle.