• 面向对象的prototype


      function Cat(){
                this.name='小白';
            }
            Cat.prototype.color='white';
            Cat.prototype.skill=function(){
                alert('吃鱼');
            }
            var cat1=new Cat();
            console.log(cat1.name);//小白
            console.log(Cat.prototype);//object
            console.log(cat1.prototype);//undefined
            console.log(cat1 instanceof Cat);//true
            console.log(cat1 instanceof Object);//true
            var obj=new Object();
            Object.prototype.abc='123';
            var str='abcd';
            var arr=['1','2','3'];
            console.log(str.abc);//123
            console.log(arr.abc);//123
            String.prototype.len=function(){
                return this.length;
            }
            alert(str.len());
            console.log(str.__proto__);//String
        
        console.log(str.constructor);// String

         console.log(str.constructor.prototype.constructor);// String

    
            console.log(str.__proto__.__proto__);//Object
            Date.prototype.getWeek=function(){
                var arr=['周末','周一','周二','周三','周四','周五','周六'];
                var index=this.getDay();//0-6
                return arr[index];
            }
            var date=new Date();
            console.log(date.getWeek());//周六
    Array.prototype.quchong=function (){
            var arr=[];
            this.sort(function (a,b){return a-b;});
            for (var i = 0; i < this.length; i++) {
                if (this[i]==this[i+1]) {
                    continue;
                };
                arr.push(this[i]);
            };
            return arr;
        }
        var arr1=[12,45,7,12,75,45,5,32,12];
        console.log(arr1.quchong());
    function fn1(){
                var x=5;
                x++;
                alert(x);
            }
            fn1();//6
            fn1();//6
            fn1();//6
            fn1();//6
            function fn2(){
                var x=5;
                function fn3(){
                    x++;
                    alert(x);
                }
                return fn3;
            }
            var fn=fn2();
            fn();//6
            fn();//7
            fn();//8
            fn();//9
  • 相关阅读:
    applications_manager很经典的应用性能监控工具
    eureka分区的深入讲解
    Spring Boot 微服务应用集成Prometheus + Grafana 实现监控告警
    solidity 学习笔记(3) 函数修饰符/继承
    以太坊
    solidity 学习笔记 2 (二维数组)
    solidity学习笔记
    女巫攻击---针对联盟链的攻击
    区块链知识点
    [转]PBFT 算法详解
  • 原文地址:https://www.cnblogs.com/SunShineM/p/6081485.html
Copyright © 2020-2023  润新知