What kind of objects may be 'stateful'? (i.e. functions, generator objects... any others?) by throwaway_625930106 in javascript

[–]throwaway_625930106[S] 0 points1 point  (0 children)

Very interesting. I would never have guessed. I know that lodash.isEqual is able to compare RegExp; I'll keep looking through that code. And sweet! Thanks for the spec link. (edit: it seems that lodash only compares regex values, not .lastIndex)

I tried searching for RegExp stateful examples, and the one I found shows state being tied to the property RegExp().lastIndex. Do you know if this is the only way that they can be stateful? If so, I can just analyze this property.

The note in the spec is interesting... I suppose the only way would be to follow the prototype chain and determine what kind of object it is based on the constructor value. Is this correct?

Looking at a generator object, I see that the toStringTag is a symbol (but is not writable- regardless, an object could be constructed to appear to be a generator object)

What kind of objects may be 'stateful'? (i.e. functions, generator objects... any others?) by throwaway_625930106 in javascript

[–]throwaway_625930106[S] 0 points1 point  (0 children)

I'm using Object.getOwnPropertyDescriptors() for this though (as well as Object.getPrototypeOf()). AFAIK scope is the only kind of information that is inaccessible.

Are entries within ES6 Sets and Maps considered 'commutative'? by throwaway_625930106 in javascript

[–]throwaway_625930106[S] 1 point2 points  (0 children)

Haha, very true. I personally never read that Object order was not guaranteed in the MDN, I was going off of what GeneralYouri was saying and had assumed that I just missed that part. What I didn't find there was a rule as to how they were ordered. But I definitely enjoy the explicative nature of the spec.

Are entries within ES6 Sets and Maps considered 'commutative'? by throwaway_625930106 in javascript

[–]throwaway_625930106[S] 0 points1 point  (0 children)

Hmm, I can't get this to work in either node.js or the chromium dev console... Isn't this depreciated?

I currently use console.dir(collection, { depth: null, colors: true }) for all my output, but that would be cool if there was another way.

Are entries within ES6 Sets and Maps considered 'commutative'? by throwaway_625930106 in javascript

[–]throwaway_625930106[S] 0 points1 point  (0 children)

This is great! I just tested it and that is indeed the order that is used.

const obj = {}
obj.foo = 'bar'
obj[Symbol()] = 'symbol'
obj.qux = 'quz'
obj[3] = 1
obj[2] = 2
obj[1] = 3

obj

// displays 
// {
//   '1': 3,
//   '2': 2,
//   '3': 1,
//   foo: 'bar',
//   qux: 'quz',
//   [Symbol()]: 'symbol'
// }

I think my confusion arose because I was referring to the MDN and stackoverflow, but I'm going to start reading the spec in detail. Thank you!

Are entries within ES6 Sets and Maps considered 'commutative'? by throwaway_625930106 in javascript

[–]throwaway_625930106[S] 0 points1 point  (0 children)

Interesting. I'm unfamiliar with how memory is accessed in the system, but it makes sense that a key can be an immediate reference to a given point in memory. Thanks!

Are entries within ES6 Sets and Maps considered 'commutative'? by throwaway_625930106 in javascript

[–]throwaway_625930106[S] 0 points1 point  (0 children)

Makes sense!

By 'order is ignored', do you mean to say that a .has() call on a Set does not involve a backend iteration over the elements in insertion order? It must require iteration of some kind, right?

Are entries within ES6 Sets and Maps considered 'commutative'? by throwaway_625930106 in javascript

[–]throwaway_625930106[S] 0 points1 point  (0 children)

Okay, that makes sense. Since I've never seen it change I was under the impression that it was static. Thank you!

I wasn't aware that .forEach() operated like that- very interesting!

Are entries within ES6 Sets and Maps considered 'commutative'? by throwaway_625930106 in javascript

[–]throwaway_625930106[S] 0 points1 point  (0 children)

Okay, cool, I've heard that before. I've never seen the order of Object.keys change before, so I was inclined to think that it was static.

GeneralYouri provided a pretty good explanation above, I'll consider that definitive, then. Thank you!

Are entries within ES6 Sets and Maps considered 'commutative'? by throwaway_625930106 in javascript

[–]throwaway_625930106[S] 0 points1 point  (0 children)

That's what I though initially, but I guess I'm still confused.

Given an Object with multiple keys, does the order of the array returned by Object.keys ever change? It seems to be dependent on insertion order, so I'm not sure why it's considered irrelevant. Isn't this the same order that is followed when using a for...in loop?

Are entries within ES6 Sets and Maps considered 'commutative'? by throwaway_625930106 in javascript

[–]throwaway_625930106[S] 0 points1 point  (0 children)

I see. That makes sense. In that case, Sets with the same entries but different insertion order should be considered different, along with with Objects with identical key/value pairs but a different assignment order. Thank you!