﻿// create the SmartPerson class and its constructor
AjaxTutorial.SmartPerson = function(name,iq) 
{
  // call the Person base class constructor
  AjaxTutorial.SmartPerson.initializeBase(this, [name]);
  this._iq = iq;

  // notify SmartPerson creation
  Sys.Debug.trace(
    String.format("{0} was created with an IQ of {1}",
                  this.get_name(), this.get_iq()));
}

// register the SmartPerson class
AjaxTutorial.SmartPerson.registerClass("AjaxTutorial.SmartPerson",
  AjaxTutorial.Person);

// define the instance members of the SmartPerson class
AjaxTutorial.SmartPerson.prototype = 
{
  // getter function for the iq property
  get_iq: function() {
    return this._iq;
  },

  // setter function for the iq property
  set_iq: function(value) {
    if(value != this._iq) {
      // create eventArgs that contains the old and new values
      var eventArgs = 
        new AjaxTutorial.PersonPropertyChangedEventArgs("IQ", 
          this._iq, value);
          
      // set the new iq and raise the change event
      this._iq = value;
      this._raiseEvent("change", eventArgs);
    }
  },
  
  // returns string description of object
  toString: function() { 
    return String.format('{{name:"{0}", IQ:{1}\}}', 
                         this._name, this._iq);  
  }
}