how do I test if a value is an object? this is my ...
# javascript
b
how do I test if a value is an object? this is my JS code:
Copy code
typeof x === 'object' && !Array.isArray(x) && x !== null;
t
Copy code
jsTypeOf(x) == "object" && x !is Array && x != null
1
v
Can it ever be
null
if the type is
object
?
t
Yes :)
null
has type
object
v
Oh, JS is really a strange language :-D
t
All this
Java*
languages are very strange 🙂
b
@Vampire you've seen thing yet, I had to work around
Copy code
class X {
    actions: {
        key: X.method
    }
    static method() {
        this.callInstanceMethod()
    }
    callInstanceMethod {
    }
    imClever ()  {
        this.actions.key.bind(this)()
    }
}
plus fighting against broken variance where
Copy code
class Model {
    static update(model: Model): Model
}
class User extends Model {}
User.update(user) // takes and returns User
I'm slowly getting where I want to be, but there were so many uphill battles
it's all very under documented as well unfortunately
t
Silver bullet for variance fixes - extensions. All
List
,
Set
,
Sequence
magic with variance - extensions.
b
t
Variance in EventTarget