日期:2014-05-16  浏览次数:20519 次

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 + "! ");
}
};