We can load javascript into the browser with javascript through dynamically created <script>
tags and we can load javascript in node with the require
method.
The code loaded in these methods can contain fully functional objects with methods in addition to properties.
Is it possible to save javascript code into a file that can then be loaded as mentioned above?
E.g., where dump_to_file
is the functionality i am looking for,
var target_object = {foo : "bar", say_foo : function(){ console.log(this.foo) }
target_object.say_foo(); // "bar"
dump_to_file("path/to/file.js", target_object)
and later, where load_from_file
is a utility defined in the first paragraph,
var target_object = load_from_file("path/to/file.js");
target_object.say_foo(); // "bar"