Joao Rodrigues wrote:
> Thomas 'PointedEars' Lahn wrote:
>> Joao Rodrigues wrote:
>>> I doubt an experienced developer would use: (1) console.log() in
>>> production code,
>> Which shows that, at the very least, you are not an experienced developer
>> yourself.
>
> /Ad hominem/ fallacy - the one you like to use most of the time.
No, it is a logical conclusion.
>> *In the right places*, console.log() can be and *is* *very
>> useful* even in production code.
>
> "Different strokes for different folks". Keep using console.log() in
> production code as you wish. If you really do what you preach, that's
> because you work alone or do not use version control systems such as
> GitHub.
Now *that* is a by-the-book /ad hominem/ argument.
Also, why do you make up things and pretend that they are true? GitHub is
_not_ a version control system (Git, which GitHub uses, is). And your claim
that I would not use such is so *obviously* false – read my sigs.
> Anyway, putting console.log() in source code is insane and unnecessary,
> given all modern browsers provide "DevTools" way more capable to debug
> code nowadays.
You are dead wrong.
Sometimes it is still necessary to use console.log() for debugging because
the interaction with the built-in debugger causes unwanted results.
Also, sometimes it is useful to have console.log() & friends in *some*
places even if one is not actually debugging the code. For example, if you
*want* to generate *messages* that only *developers* need to see.
>> The very point of linters like JSLint is to make sure that it does not
>> appear *unintentionally* in *production* code, as a remnant of debug
>> code.
>>
>> Annotating “console” as an implicit global for the whole file, as you
>> suggested, *counteracts* this benefit. (Except, AISB, if it is a *debug*
>> library.)
>>
>>> (2) an obsolete and opinionated linter such as JSLint.
>>
>> The same is true for other linters *by default*, so that argument does
>> not hold water.
>
> Nonsense.
It is not nonsense. *For example*, JSHint will by default produce a warning
on the use of “console”, too, because it does not need to be defined in
order to be used; so that is not at all “opinionated” of JSLint.
[If you want to remember, you had made that argument yourself; I am
merely repeating it. Unfortunately, one can observe here again that
you "forget" your own arguments when they become inconvenient for you.]
However, maybe by contrast to JSLint, JSHint provides several ways in which
to disable that warning in *some* places where the use of “console” was
*intentional*.
>>>>> Of course ESLint, JSHint and JSLint warn about undeclared use of
>>>>> 'console' and its methods. JS Linters 101.
>>>> That is simply untrue. As I have showed, it depends on the
>>>> configuration.
>>> The default configuration of all those linters will warn about the use
>>> of console.log() (and missing semicolons where they are expected).
>> But this is a fundamentally different statement than the one that you
>> made before.
>
> How did you get that idea?
That is *self-evident*. The second statement is more restrictive.
>>>>>>>> and it says it needs a semi colon after the data object?
>>>>>>> Sure does. A semicolon is required in the end of a statement.
>>>>>> No, in general it is not.
>>>>> Nonsense. If semicolons were really optional there would not be a
>>>>> thing called "Automatic Semicolon Insertion" (ASI) in the
>>>>> Specification, which states:
>>>> You have no clue what you are talking about.
>>> You too!
>> LOL.
>
> That was hilarious indeed.
It was. Your overconfident ignorance is most refreshing at times.
Have you ever heard of the Dunning–Kruger effect?
There is no FM to read because none corroborates your claim. You have a
misconception there.
>>> Your logic is flawed.
>> No, yours is.
>
> You are trying to shift the burden of proof.
Not at all. I have provided the proof already, but you are ignoring (and
not quoting) it. As if that would make it disappear and people would not
remember.
Here is another one:
/* somewhere in code that the OP’s code uses */
Object.prototype.answer = 42;
/* lots of LOCs */
/* OP’s code */
const data = {
"foo": "bar",
"baz": "bla"
};
You have called what the right-hand side of the latter statement evaluates
to a “dictionary-like object”. But when assuming the former statement *or
something built-in to the same effect*, one finds:
/* 42 */
console.log(data["answer"]);
var keys = [];
for (var name in data)
{
keys.push(name);
}
/* _at least_ ["answer", "foo", "baz"] */
keys
A “dictionary-like object” simply does not behave like this. It would _not_
contain keys that have _not_ been added to it explicitly.
This refutes your argument that the referred object would be such an object,
and proves that you have not understood “prototypal inheritance” in
ECMAScript (implementations).
Not filtering for-in loops is unwise in *any* case, unless the prototype
chain of the object iterated over is empty. (And even then there is the
remote possibility that a built-in enumerable property exists.)
As I indicated before, such an object can, for example, be created thus:
const data = Object.assign(Object.create(null), {
"foo": "bar",
"baz": "bla"
});
This is basically what
const data = jsx.object.createDataObject({
"foo": "bar",
"baz": "bla"
});
does.
/*
* jsx.object.getKeys() basically does this, as does the native
* Object.keys() now (JSX had it first)
*/
var keys = [];
for (var name in data)
{
keys.push(name);
}
/* _virtually guaranteed_ ["foo", "baz"] */
keys