I just did some tests and indeed, it does return iterable Object, but i would be glad to see implementation how to make instance return iterable Object like Set does.
Well, took me some time to get trought specs and all the ressources, so far found out how to return iterable object from class methods. In shared post of Stack Overflow there was github repo with implementation of Set es6-set/polyfill.js at master · medikoo/es6-set · GitHub but its including functions which can’t be found there, like
, d = require('d')
Still looking for a way to make object looks as follow:
I don’t think I’m following what you are asking here? Are you asking how to make it print out a certain way when you do a console.log? The formatting used in a console.log is up to the console. For example, if I console.log a Set in FF 92 on linux it prints out using square brackets but if I do the same thing in node it uses curly braces. If you want to have complete control over this you should write your own method that creates the string you want and then console.log that string.
But I’m not exactly sure this is what you are asking. If not can you be a little more specific?
Read again the question, I simplyfy it enought, even begginer programmers could catch it. Don’t go qround the topic, there is only one problem to solve, dont look for new ones.
Again… how the object appears with console.log() has absolutely zero bearing on how it actually functions, so what goal are you actually trying to achieve by changing how this object console.log()s?
How something is console.log()ed is controlled by the JavaScript implementation and has absolutely nothing to do with how it behaves. You would have to dig into different JS engines to see how each engine decides to console.log() different objects and user defined objects.
You have zero ability to control how something appears when console.log()ed. JS doesn’t have __str__() or __repr__() the way that Python does.
Well i didn’t ask about python but good to know.
Implementations have to follow the specs, so the only difference in given output of Set object is beside curly and square brackets
If anyone know how to make Iterator Object appear in same way as native Set does J would be glad if anyone share the knowledge
I’ve peeked at descriptors of Set, and the only one thing which i couldnt imitiate in same way as is showed below is the marked property. It may be the key
The logger operation accepts a log level and a list of other arguments. Its main output is the implementation-defined side effect of printing the result to the console. This specification describes how it processes format specifiers while doing so.
Its main output is the implementation-defined side effect of printing the result to the console.
The printer operation is implementation-defined. It accepts a log level indicating severity, a List of arguments to print, and an optional object of implementation-specific formatting options. Elements appearing in args will be one of the following:
The printer operation is implementation-defined.
So, again, the output from console.log() is IMPLEMENTATION SPECIFIC and HAS ZERO BEARING ON HOW THE OBJECT BEHAVES.
If you want to know how the logging happens in a particular JS engine, you need to dig into that engine’s implementation. JS does not offer control over the display of user defined objects in the way that Python does.
And sometimes specs don’t specify every minute detail such as how to display something in console output. These types of decisions are left up to the vendor.
One idea I have for you is to override the toString method on your custom set and then force it to be displayed as a string when you send it to console.log.
Yup. You can create a custom method to override toString() and then you can determine the output from console.log(mySuperSpecialSet.toString()) or console.log("" + mySuperSpecialSet), but you have no control over console.log(mySuperSpecialSet).
Its not about beliving, everything is doable just need to find out way how.
Tryed it already, its working but would like to get same behaviour as the native Set.
Just to make it clear, it isn’t question from beginner or newbie, its open discussion. If anyone know how to imitiate native Set behaviour feel free to share;
This is unfortunately not true. The JS language standard very specifically contradicts you here. console.log()'s behavior is implementation specific. No tools in the language specification exist for you to control this.
The fact that you don’t believe the language specification as written is not the fault of the language specification.