« Posts under Java Script

Javascript Complete Object Serialization (JSON) with Methods (Object Type) and Circular References

Object serialization can be a powerful feature for transferring or persisting objects, but when using JSON  serialization with JSON.stringify()  you have to keep in mind some things:

  • Values that do not have a representation in JSON (such as functions and undefined) are excluded
  • Objects are stored as ‘Object’ without a prototype reference
  • Circular references within an object can cause an error: too much recursion

If you want to have those features get cycle.js do it like this:

 

 

 

Google translate with PhantomJS

PhantomJS is a headless browser which is controlled by Java Script statements.

Here is a small sample for using Google translate:

Save this code as gtranslate.js and put jquery.min.js within the same directory.