zoukankan      html  css  js  c++  java
  • 语言精粹【摘要】

    if (typeof Object.beget !== 'function') {

    Object.beget = function (o) {
    var F = function () {};
    F.prototype = o;
    return new F();
    };
    }
    var another_stooge = Object.beget(stooge);

    Function.prototype.method = function (name, func) {
    if (!this.prototype[name]) {
    this.prototype[name] = func;
    }
    };

    Object.method('superior', function (name) {
    var that = this,
    method = that[name];
    return function ( ) {
    return method.apply(that, arguments);
    };
    });

    var mammal = function (spec) {
    var that = {};

    that.get_name = function ( ) {
    return spec.name;
    };

    that.says = function ( ) {
    return spec.saying || '';
    };

    return that;
    };

    var myMammal = mammal({name: 'Herb'});

    var cat = function (spec) {
    spec.saying = spec.saying || 'meow';
    var that = mammal(spec);
    that.purr = function (n) {
    var i, s = '';
    for (i = 0; i < n; i += 1) {
    if (s) {
    s += '-';
    }
    s += 'r';
    }
    return s;
    };
    that.get_name = function ( ) {
    return that.says( ) + ' ' + spec.name +
    ' ' + that.says( );
    }
    return that;
    };
    var myCat = cat({name: 'Henrietta'});
    var coolcat = function (spec) {
    var that = cat(spec),
    super_get_name = that.superior('get_name');
    that.get_name = function (n) {
    return 'like ' + super_get_name( ) + ' baby';
    };
    return that;
    };

    var myCoolCat = coolcat({name: 'Bix'});
    var name = myCoolCat.get_name( );
    // 'like meow Bix meow baby'

  • 相关阅读:
    用mysql++读写二进制
    mysql++的release版本当机的问题
    mongo的安装
    什么是新装用电和增加用电
    填写用电报装申请表
    湖南省居民生活阶梯电价政策问答
    什么是阶梯电价
    用case when 动态给sql 添加 查询条件
    js 原型 继承
    可编辑的表格
  • 原文地址:https://www.cnblogs.com/dingyuanxin/p/4064991.html
Copyright © 2011-2022 走看看