链式编程

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script type ="text/javascript">
        var per = new Object();
        per.name = "张三";
        per.age = 10;
        per.growUp = function () {
            this.age++;
            return this;//链式编程的关键是方法返回当前的这个对象
        }

        per.sayHi = function () {
            alert(this.name+"age="+this.age);
        }
        per.growUp().growUp().sayHi();
    </script>
</head>
<body>

</body>
</html>

  

posted @ 2014-06-13 23:22  编程猴子  阅读(358)  评论(0编辑  收藏  举报