一切皆对象之两个方法概括js,无函数签名(无多态),原型,闭包,封装,引用类型,继承……

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script type="text/javascript">

    var num = [88, 1151, 1];
    (function() {
        /**
         * 对于n1,n2,n3;如果其中任意两个分别乘以[1, 100]范围内的任意两个整数x,y的和加2或者减2等于
         * 另外第三个数,找出x和y.
         * @type {Number}
         */
        function MioFun () {
            this.a = arguments[0][0];
            this.b = arguments[0][1];
            this.c = arguments[0][2];
        }
        MioFun.prototype = {
            constructor : MioFun,
            findMax: function() {
                var temp = 0;
                if(this.a < this.b) {
                    temp = this.a;
                    this.a = this.b;
                    this.b = temp;
                }
                if(this.a < this.c) {
                    temp = this.a;
                    this.a = this.c;
                    this.c = temp;
                }
                return this;
            },
            calMain: function() {
                var i, j;
                if(this.a < this.b + this.c) return null;
                for(i = 1; i <= 100; i++) {
                    for(j = 1; j <= 100; j++) {
                        this.calFun(i, j);
                    }
                }
            },
            calFun: function(x, y) {
                if((this.a-2 == this.b*x + this.c*y)||(this.a+2 == this.b*x + this.c*y)) {
                    console.log(x, y, this.b + "*" + x + "+" + this.c + "*" + y + "=" + (this.a - 2) + "or" + (this.a + 2));
                    console.log("");
                }            
            }
        }
        var mio = new MioFun(arguments[0]);
        mio.findMax().calMain();        
    })(num);







    var arg = [88, 1152, 102];
    (function() {
        /**
         * 对于n1,n2,n3;如果其中任意两个分别乘以[1, 100]范围内的任意两个整数x,y的和加2或者减2等于
         * 另外第三个数,找出x和y.
         * @type {Number}
         */
        function SuperFun () { //父类成员属性
            if(arguments[0]) {
                this.a = arguments[0][0];
                this.b = arguments[0][1];
            }
        }
        SuperFun.prototype.findMax = function() { //父类成员方法findMax
            var temp = 0;
            if(this.a < this.b) {
                temp = this.a;
                this.a = this.b;
                this.b = temp;
            }
            if(this.a < this.c) {
                temp = this.a;
                this.a = this.c;
                this.c = temp;
            }
            return this;
        };
        SuperFun.prototype.calFun = function(x, y) { //父类成员方法calFun
            if((this.a-2 == this.b*x + this.c*y)||(this.a+2 == this.b*x + this.c*y)) {
                console.log(x, y, this.b + "*" + x + "+" + this.c + "*" + y + "=" + (this.a - 2) + "or" + (this.a + 2));
                console.log("");
            }            
        };
        function SubFun () {
            SuperFun.call(this, arguments[0]); //继承父类SuperFun属性
            this.c = arguments[0][2]; //子类伪私有成员属性
        }
        SubFun.prototype = new SuperFun();  //继承父类SuperFun方法
        SubFun.prototype.constructor = SubFun;
        SubFun.prototype.calMain =  function() { //子类伪私有成员方法
            var i, j;
            if(this.a < this.b + this.c) return null;
            for(i = 1; i <= 100; i++) {
                for(j = 1; j <= 100; j++) {
                    this.calFun(i, j);
                }
            }
        };       
        var mio = new SubFun(arguments[0]);
        mio.findMax().calMain();        
    })(arg);
	</script>
</head>
<body>
	
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值