This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let obj = { "key": "value" }; | |
| let myString = obj.toString(); | |
| console.log(myString); | |
| // '[object Object]' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let obj = { "key": "value" }; | |
| let myString = JSON.stringify(obj); | |
| console.log(myString); | |
| // '{"key":"value"}' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let obj = { "key": "value" }; | |
| let myString = JSON.stringify(obj, null, 4); // 4 space indentations | |
| console.log(myString); | |
| // { | |
| // "key": "value" | |
| // } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let obj = { "key": "value" }; | |
| let myString = JSON.stringify(obj, null, '\t'); // tab | |
| console.log(myString); | |
| // { | |
| // "key": "value" | |
| // } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let str = '{ "a": 123 }'; | |
| let obj = JSON.parse(str); | |
| console.log(obj); | |
| // { a: 123 } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'dart:async'; | |
| import 'dart:isolate'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Future<SendPort> initIsolate() async { | |
| Completer completer = new Completer<SendPort>(); | |
| ReceivePort isolateToMainStream = ReceivePort(); | |
| isolateToMainStream.listen((data) { | |
| if (data is SendPort) { | |
| SendPort mainToIsolateStream = data; | |
| completer.complete(mainToIsolateStream); | |
| } else { | |
| print('[isolateToMainStream] $data'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void myIsolate(SendPort isolateToMainStream) { | |
| ReceivePort mainToIsolateStream = ReceivePort(); | |
| isolateToMainStream.send(mainToIsolateStream.sendPort); | |
| mainToIsolateStream.listen((data) { | |
| print('[mainToIsolateStream] $data'); | |
| }); | |
| isolateToMainStream.send('This is from myIsolate()'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() async { | |
| SendPort mainToIsolateStream = await initIsolate(); | |
| mainToIsolateStream.send('This is from main()'); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Example of bi-directional communication between a main thread and isolate. | |
| import 'dart:io'; // for exit(); | |
| import 'dart:async'; | |
| import 'dart:isolate'; | |
| Future<SendPort> initIsolate() async { | |
| Completer completer = new Completer<SendPort>(); | |
| ReceivePort isolateToMainStream = ReceivePort(); |
OlderNewer