標高+1m

Don't be rational

prototypeとthisを使わずにうまいこと継承書けないかな

function __extend (dst, src) {
  var key;
  for (key in src) 
    if ({}.hasOwnProperty.call(src, key))
      dst[key] = src[key];
  return dst;
}

var Animal = function (opts) {
  var self
  self = {
    name: '',
    sound: '',
    init: function (opts) {
      __extend(self, opts);
    },
    quack: function () {
      alert(self.sound);
    },
    walk: function (metre) {
      alert(self.name+' moved '+metre+'m.');
    }
  };
  self.init(opts);
  return self;
};

var Snake = function (opts) {
  var self;
  self = __extend(Animal(opts), {
    sound:'Shhhh',
    walk: function () {
      window.alert(self.name +' is crawling');
      self._super.walk(5);
    },
    _super: Animal(opts)
  });
  return self;
};

var sam = Snake({name: 'Sammy the Python'});
sam.quack();
sam.walk();