• 夺命雷公狗---javascript NO:20 面向对象历史起源


    1、软件编程发展史

    • 面向机器
    • 面向过程
    • 面向对象

    案例:传智ERP系统

    咨询()à报名()à缴费()à分班()à学习()à就业()

    面向过程:把一个系统分解为若干个步骤,每个步骤就是一个函数

    function 咨询() {}

    function 报名() {}

    function 缴费() {}

    咨询();

    报名();

    缴费();

    面向对象:把一个系统分解为若干个事务,每个事务就是一个类

    学生

    老师

    财务

    class Student() {

    function 咨询() {}

    function 报名() {}

    function 缴费() {}

    }

    $stu = new Student();

    $stu->咨询();

    2、两个基本概念

    • 类:代表某类事物,是抽象的
    • 对象:代表某个事物,是具体的

    3、面向对象分类

    系统类

    自定义类(重点)

    4、常用的系统类

    1)String字符串类

    • length :返回字符串的长度
    • indexOf(string) :返回参数在字符串中的位置(默认从0开始)
    • substr(num1,[num2]):截取指定长度的字符串
    • toLowerCase() :转化为小写
    • toUpperCase() :转化为大写
    • replace(str1,str2):字符串替换

    2)Date日期时间类

    • getYear() :返回年份(有兼容性问题)
    • getFullYear() :返回年份
    • getMonth() :返回月份(0-11)
    • getDate()  :返回日期(1-31)
    • getDay() :返回星期几(0-6)
    • getHours():返回小时
    • getMinutes():返回分钟
    • getSeconds() :返回秒数
    • getMilliseconds():返回毫秒数
    • getTime():返回时间戳

    3)Math数学类

    • ceil(数值) :返回大于或等于该数的最小整数
    • floor(数值) :返回小于或等于该数最大整数
    • min(数值1,数值2):返回最小值
    • max(数值1,数值2) :返回最大值
    • pow(数值1,数值2) :返回数值1的数值2次方,2的2次方=4
    • random() :返回0-1之间的随机小数
    • round(数值):返回四舍五入后的结果
    • sqrt(数值) :返回开平方,16的开平方=4

    示例代码:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset=’utf-8′>
    <title></title>
    </head>
    <body>
    <script>
    //string类,在javascript可以通过单引号或者双引号创建string类的实例化
    var str = ‘hello,php';
    document.write(‘字符串的长度’+str.length);
    document.write(‘<hr/>’);
    document.write(‘转化为大写’+str.toUpperCase());
    document.write(‘<hr/>’);
    document.write(‘替换后的字符串’+str.replace(‘php’));
    document.write(‘<hr/>’);
    //date日期和时间类
    var date = new Date();
    document.write(‘当前日期’+date.getFullYear()+”-“+(date.getMonth()+1)+’-‘+date.getDate());
    document.write(‘<hr/>’);
    //Math数字类,在javascript中的math教学类中,其所有属性和方法都是静态的
    var num = 10.88;  //定义一个Number类型的数据
    document.write(‘返回大于等于num的最小整数’+Math.ceil(num));
    document.write(‘<hr/>’);
    document.write(‘返回随机数’+Math.random());
    </script>
    </body>
    </html>
  • 相关阅读:
    上班5个月总结
    使用余弦定理计算两篇文章的相似性
    9月10日 小结
    软件测试
    《增长黑客》笔记
    统计学术语
    数据分析师:数据分析工作常见七种错误及其规避技巧(转自经管之家)
    输入一个日期,计算这个日期与 2018-03-12差多少天;
    求输入数字的阶乘 及加和 #s=1!+2!+3!+…..+n!
    列表去重
  • 原文地址:https://www.cnblogs.com/leigood/p/5031928.html
Copyright © 2020-2023  润新知