11.08笔记整理及心得
2017-11-08 17:06
120 查看
11.08课堂笔记以及学习心得
1、对象及其构造方法
1.1什么是对象
世间任何一个我们需要进行研究的事物都是一个对象。对象具有状态,一个对象用数据值来描述它的状态。对象还有操作,用于改变对象的状态,对象及其操作就是对象的行为。2.2 构造对象的方法
var student={ 'name':'张三', 'age':30, 'health':100000, 'java':50, 'study':function(){ this.java=this.java+2; }, 'eat':function(){ this.health=this.health+100; }, 'smoke':function(){ this.health=this.health-1000; } } //创建对象 student.study(); console.log(student.name);
var student=new Object(); //新建对象 student.name='张三'; student.sex='男'; student.age=30; student.health=10000; student.java=50; //添加属性 student.study=function(){ this.java+=2; } student.time=function(){ this.age+=1; } student.smoke=function(){ this.health-=1000; } //创建行为 student.smoke(); //调用方法 console.log(student.health); student.time(); student.study(); console.log(student);
2、变量
2.1语句
语句是完成某种特定任务的代码,在javascript中每条语句要以”;”结束。2.2变量
变量是对“值”的引用。在其他的场合中,我们有的时候把引用也成为地址或指针。在js中使用”var”关键字定义变量。
var sidebar="hello"; var sidebar; sidebaar="hello";
2.3输出语句
使用 console.log() 写入到浏览器的控制台。console.log(student.name);
2.4 标识符和注释
(1)、标识符- 第一个字符:任意的Unicode字母(包含英文字母和其他语言的字母),以及美元符号$和下划线_;
- 第二个字符及后面的字符开始可以包含0-9的数字;
(2)、注释
单行注释://
多行注释:/**/
3、条件语句
3.1 if机构
var student=new Object(); //新建对象 student.name='张三'; student.sex='男'; student.age=25; student.health=10000; student.house=3; student.car=2; student.money=1000; student.handsome=85; student.work=function(){ this.money+=200; this.house+=1; this.car+=1; this.age+=5; } student.sport=function(){ this.handsome+=1; this.health+=100; } student.smoke=function(){ this.health-=1000; } if(student.age>30){ console.log('大叔,我们不约'); }else if(student.house>=5&&student.car>=4&&student.money>=1200&&student.health>=8000){ console.log('你很棒,我们在一起吧'); }else if(student.house>=4&&student.car>=3&&student.money>=1100&&student.health>=8000){ console.log('还不错,可以相处试试看'); }else{ console.log('洗洗睡吧'); } console.log(student.name+'发奋努力,勤奋工作'); student.work(); if(student.age>30){ console.log('大叔,我们不约'); }else if(student.house>=5&&student.car>=4&&student.money>=1200&&student.health>=8000){ console.log('你很棒,我们在一起吧'); }else if(student.house>=4&&student.car>=3&&student.money>=1100&&student.health>=8000){ console.log('还不错,可以相处试试看'); }else{ console.log('洗洗睡吧'); } console.log(student.name+'继续发奋努力,勤奋工作'); student.work(); if(student.age>30){ console.log('大叔,我们不约'); }else if(student.house>=5&&student.car>=4&&student.money>=1200&&student.health>=8000){ console.log('你很棒,我们在一起吧'); }else if(student.house>=4&&student.car>=3&&student.money>=1100&&student.health>=8000){ console.log('还不错,可以相处试试看'); }else{ console.log('洗洗睡吧'); }
3.2 while循环语句
用于重复执行某些操作。var student=new Object(); //新建对象 student.name='张三'; student.sex='男'; student.age=25; student.health=10000; student.sport=function(){ this.health+=100; } student.smoke=function(){ this.health-=1000; } var i=1; while(student.health<=12000){ i+=1; student.sport(); console.log(student.name+'经过'+i+'次健身,当前健康值为:'+student.health); }
3.3 嵌套语句
var student=new Object(); //新建对象 student.name='张三'; student.sex='男'; student.age=25; student.health=10000; student.sport=function(){ this.health+=100; } student.smoke=function(){ this.health-=1000; } for(var k=1; student.health>=8000;k++){ student.smoke(); console.log(student.name+'经过'+k+'次抽烟,当前健康值为:'+student.health); if(student.health<=9000){ console.log('抽烟有害健康,请戒烟'); } }
11.08学习心得
今天学习了JavaScript基础,了解变量对象等概念。Java把内存分成两种:一种是栈内存,一种是堆内存。栈的优势是,存取速度比堆要快,仅次于寄存器,栈数据可以共享。但缺点是,存在栈中的数据大小与生存期必须是确定的,缺乏灵活性。栈中主要存放一些基本类型的变量。var val1=new Object(); var val2=val1; val2.name=86; console.log(val1); //val1被赋予'name'属性 //val1被赋予val2,但是val1没有数据,将存储地址赋予val2,所以val1和val2指向同一个堆内存地址。
相关文章推荐
- 信安 web 的一些心得与笔记整理(1)
- 11.10笔记整理、作业和学习心得
- 学术写作利器——LaTeX入门笔记整理(不定期更新,附加使用心得)
- 11.07笔记整理、作业及学习心得
- 复习,整理笔记 心得
- JAVA基础学习精简心得笔记整理
- 有关c#的学习笔记整理与心得
- 11.06笔记整理、作业以及学习心得
- 信安 web 的一些心得与笔记整理(2)_实验吧WEB题的简要整理
- 【整理】HTML5游戏开发学习笔记(3)- 抛物线运动
- ZThread多线程库学习笔记整理二
- 【Python】Python学习笔记——读书心得
- C++Primer 1.2章笔记整理
- Leetcode笔记(整理中.......)
- Deep Learning(深度学习)学习笔记整理系列之(二)
- JS性能优化笔记搜索整理
- 笔记整理----python
- trait学习 笔记整理
- 【整理】Xcode中的iOS模拟器(iOS Simulator)的介绍和使用心得
- c traps and pitfalls整理笔记