Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var test = function(){
- this.name = 'Lluis';
- this.age = 30;
- }
- test.prototype = {
- sayMyName: function(){
- console.log(this.name);
- },
- toSource: function(){
- return JSON.stringify(this);
- }
- }
- var obj = new test();
- obj.sayMyName(); //prints Lluis
- obj.name = 'Alessio';
- obj.age = 36;
- obj.country = 'Italy';
- obj.sayMyName(); //prints Alessio
- var str = 'Obj ' + obj.toSource();
- console.log(str); //prints Obj {"name":"Alessio","age":36,"country":"Italy"}
Add Comment
Please, Sign In to add comment