• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
余苏益
博客园    首页    新随笔    联系   管理    订阅  订阅
11.4 基本语法 创建对象
基本语法
/*
     \d 0-9任意一个数字
     []  其中的任意一个字符
     [0-9] \d
       12 =>  [1][2]  12
       [12a] 1、2、a
       [a-zA-Z0-9]
       [^] 非其中的任意一个字符
       [^0-9]
       \w 数字 字母 下划线
       .  任意一个字符
       [.] .
       |  或
       2|3   2、3
       1[0-2]
       1[012]

       ?  0-1次
        0? [1-9]
        +  1-多次
        * 0-多次
        {,}  最少,最多
        {6,12}
        {6,}
        {,12}

        ^  开始
        $ 结束
*/
 
// 字面量
var student={
    id:10001,
    name:"张三",
    scores:[
        {subject: "html",score: 90}
        {subject: "JS",scros: 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="男";
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.id = 1000;
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:10  余苏益  阅读(70)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3