Prototype1.5.1源代码解读分析-5

< DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd>
Abstract源代码

var Abstract = new Object();

代码解析及其使用方法

Abstract(抽象类)是个空类,没有任何成员。

Object.extend源代码

Object.extend = function(destination, source) {

  for (var property in source) {

    destination[property] = source[property];

  }

  return destination;

}

Object.extend(Object, {

  inspect: function(object) {

    try {

      if (object === undefined) return 'undefined';

      if (object === null) return 'null';

      return object.inspect ? object.inspect() : object.toString();

    } catch (e) {

      if (e instanceof RangeError) return '...';

      throw e;

    }

  },

  toJSON: function(object) {

    var type = typeof object;

    switch(type) {

      case 'undefined':

      case 'function':

      case 'unknown': return;

      case 'boolean': return object.toString();

    }

    if (object === null) return 'null';

    if (object.toJSON) return object.toJSON();

    if (object.ownerDocument === document) return;

    var results = [];

    for (var property in object) {

      var value = Object.toJSON(object[property]);

      if (value !== undefined)

        results.push(property.toJSON() + ': ' + value);

    }

    return '{' + results.join(', ') + '}';

  },

  keys: function(object) {

    var keys = [];

    for (var property in object)

      keys.push(property);

    return keys;

  },

  values: function(object) {

    var values = [];

    for (var property in object)

      values.push(object[property]);

    return values;

  },

  clone: function(object) {

    return Object.extend({}, object);

  }

});

posted @ 2007-08-16 23:38  netcorner  阅读(231)  评论(0编辑  收藏  举报