Skip to content

in keyword compiles to unnecessarily awkward js... #2562

@torvalamo

Description

@torvalamo

Unless I'm missing something,

if a in array
unless a in array

should simply compile to

if (~array.indexOf(a))
if (!~array.indexOf(a))

rather than the incredibly contrived

var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

if (__indexOf.call(array, a) >= 0)
if (__indexOf.call(array, a) < 0)

What ancient browser are you trying to support that doesn't have indexOf on arrays? At the very least learn what the tilde operator does ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions