js学习(三)-使用大括号({ })语法创建无类型对象

//----------------------js代码-------------------

var user = {
  name:'tom',
  say:function(){
  console.log("hello");
  }
}

//----------------------html页面代码-------------------

<script type="text/javascript" >
  user.age = 25;//给user添加属性
  user.sayHello = function(){//给user添加方法
    console.log("hello other");
  }

  console.log(user['name']);
  console.log(user['age']);
  console.log(user['sayHello']);
</script>

 

posted @ 2018-05-18 10:06  baby孔祥超  阅读(455)  评论(0编辑  收藏  举报