2021/11/4基本语法

\d   0-9任意数字    \D
    []     任意一个字符
           12 =>  [1][2]   12    匹配电话可以用
           [12a]  匹配1或2或a
           [a-z A-Z 0-9_]
    [^]    非其中的任意一个字符
            [^0~9]
    \w     数字、字母、下划线
    .       任意一个字符  包括空格包括换行
     
    |      代表  或
            例:2|3  2、3



    ?      0-1次
           0?[1-9]  0可以有也可以没有
    +      1-多次
    *      0-多次
    {,}    最少,最多
           {6,12}
           {6,}  至少六个
           {,12}  最多十二个

 

    ^      代表开始
        代表结束
 
 
var txt = "123abc456";
var reg=/\d+/
 只要其中有一部分满足 第二个 结果就为true
 
 
 
var txt = "12v3";
var reg = /^\d+$/     //如果内容全是数字 则 结果为TRUE  若以字母开头则结果为false
                              // 开始与结束都为数字结果为true
console.log(reg.test(txt))
 
 
1[3-9]\d{9}  
\d{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[12][0-9]|3[01])  年月日日期
[\u4e00-\u9fa5]  常用汉字范围
 \u4e00\u4e00  单字节
 
 
JS的调用方法:
第一种:
var student={
    id:10001,
    name:"张三",
    scores:[
        {subject:"html",score:90},
        { subject:"JS",score:90}
    ]
}
console.log(student.scores);     //调用结果
 结果为:
[ { subject: 'html', score: 90 }, { subject: 'JS', score: 90 } ]
 
第二种:利用function
function Student(id,name){
    this.id = id;
    this.name = name;
    this.scores = [
        {subject:"html",score:90},
        { subject:"JS",score:90}
    ]
Student.prototype.sex="男";          //prototype   代表   扩充
Student.prototype.eat = function(food){    //扩展   
    console.log("吃" + food)
}
var stu = new Student(1000,"张三");
stu.eat("米饭");
console.log(stu.sex)
结果为:
吃米饭
 
Object  第三种:
 
var stu2 = new Object();
stu2.name="张三";
stu2.scores =[
    {subject:"html",score:90},
    { subject:"JS",score:90}
]
 
链式编程:
function Student(id,name){
    this.id = id;
    this.name=name;
 
    this.eat =function(food){
        console.log("吃"+food)
        return this
    },
    this.sleep = function(){
        console.log("睡")
        return this
    }
}


var stu = new Student(1001,"张三");
stu.eat("").sleep().eat("").sleep().eat("").sleep().eat("").sleep();        //链式编程
 
 


posted on 2021-11-04 17:50  闲鱼仔  阅读(45)  评论(0)    收藏  举报