读书人

Javascript 中的沿袭

发布时间: 2012-11-25 11:44:31 作者: rapoo

Javascript 中的继承

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head>    <title>Javascript 中的继承</title>    <script type="text/javascript">        function Person(name) {            this.name = name;        }                Person.prototype.getName = function() {            return this.name;        }                function Man(name, sex) {            Person.call(this, name);            this.sex = sex;        }                Man.prototype = new Person();                Man.prototype.getSex = function() {            return this.sex;        }                var person = new Person('stefan');        var mPerson = new Man('stefan2', 'man');                alert(person.getName());                alert(mPerson.getName());        alert(mPerson.getSex());    </script></head><body></body></html>

读书人网 >JavaScript

热点推荐