www.webdeveloper.com
Results 1 to 1 of 1

Thread: Reassigning myobject.prototype to change classes?

  1. #1
    Join Date
    Dec 2006
    Posts
    48

    Reassigning myobject.prototype to change classes?

    Hey everyone, do you think this is okay javascript? Anyone ever done something like this before?

    Code:
    function Person() { }
    Person.prototype.sayHi = function() { alert("Hello!"); }
    
    var myperson = {id: 3004, name: "Goobles"};
    myperson.prototype = Person.prototype;
    myperson.sayHi();
    I've never changed the prototype manually. I'm experimenting with it because JSON just returns everything as plain Objects. I need the JSON to return Persons so I can call sayHi on them, but the only way I can think of doing that is to change the prototype.

    Tried googling, but all that came up was the Prototype framework. Wish they named their framework differently.

    PS. Sorry for the double-post, I was trying to edit the title and something weird happened.
    Last edited by Verdagon; 07-31-2009 at 11:02 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles