zoukankan      html  css  js  c++  java
  • 5月17日上课笔记-js面向对象

    二、js面向对象
        js创建对象:
            var 对象名称 = new Object();
            person.name = "小明"; //姓名
            person.age = 18;
            person.location = "合肥";
            person.showName = function(){
                alert(this.name);
            }
            //调用属性
            //alert(person.name);
            person.showName();
        字面量创建对象:
            JSON格式
                var person={
                    name:"",
                    age:16
                }
        内置对象:
            String(字符串)对象
            Date(日期)对象
            Array(数组)对象
            Boolean(逻辑)对象
            Math(算数)对象
            RegExp对象
                var reg = /^1[34587]d{9}$/;  //正则表达式
                reg.test(value); //验证
        构造函数:
            //构造方法
            function Person(name,age,location,score){
                this.name = name;
                this.age = age;
                this.location = location;
                this.score = score;
                //成员方法
                this.show = function(){
                    alert(this.name+"--"+this.age);
                }
            }
        构造方法属性:
            对象.constructor
            
        原型对象(类似父类)
        原型链(类似java的多重继承)
            Man.prototype = new Humans();
        借用构造函数实现继承:
            function Humans(){
                this.sex = "男";
                this.name="大黄";
            }
            function Man(){
                //借用构造函数实现继承
                Humans.call(this);   //继承了Humans,同时还传递了参数
                this.age=38;              //实例属性
            }
            
    志存高远,脚踏实地!
  • 相关阅读:
    计算某一日期是在一年中第几周
    动态生成web表-asp.net table
    sql server 小技巧(7) 导出完整sql server 数据库成一个sql文件,包含表结构及数据
    循环取月的三位英语名 Jan Feb
    Python面向对象编程
    算法
    UDP Sockets in C#
    C++ 11
    GNU Make
    C++ 11
  • 原文地址:https://www.cnblogs.com/benben2013A/p/7058079.html
Copyright © 2011-2022 走看看