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?
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
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.
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).
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.