当前位置: 代码迷 >> JavaScript >> prototype.js中的Class.create()的有关问题
  详细解决方案

prototype.js中的Class.create()的有关问题

热度:116   发布时间:2012-03-14 12:01:12.0
prototype.js中的Class.create()的问题
照着网上的例子打得,可就是输出,求高手指教
<?xml   version= "1.0 "   encoding= "UTF-8 "   ?>
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN ">
<html   xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=UTF-8 "   />
<title> Prototype   Number   Example </title>
<script   type= "text/javascript "   src= "../../js/prototype.js "> </script>
<script   type= "text/javascript ">
var   Animal   =   Class.create();
Animal.prototype   =   {
    initialize:   function(name,   sound)   {
        this.name     =   name;
        this.sound   =   sound;
    },

    speak:   function()   {
        alert(name   +   "   says:   "   +   sound   +   "! ");
    }
};

var   snake   =   new   Animal( "Ringneck ",   "hissssssssss ");
snake.speak();

var   Dog   =   Class.create();

Dog.prototype   =   Object.extend(new   Animal(),   {
    initialize:   function(name)   {
        this.name     =   name;
        this.sound   =   "woof ";
    }    
});

var   fido   =   new   Dog( "Fido ");
fido.speak();
</script>
</head>
<body>


</body>
</html>

------解决方案--------------------
create() -> Function
Returns an function that acts like a Ruby class.

------解决方案--------------------
speak: function() {
alert(this.name + " says: " + this.sound + "! ");
}
};
  相关解决方案