javascript系列学习----对象相关概念理解
2024-09-23 11:59:07
1、构造函数(相对于面向对象编程语言里面的类)
2、对象实例(它是由构造函数构造出来的对象,使用到关键字 new)
3、this关键字(往往是指我们的对象本身)
下面我们来看一个实例:
var Person = function Person(living, age, gender) {
// "this" below is the new object that is being created (i.e. this = new Object();)
this.living = living;
this.age = age;
this.gender = gender;
this.getGender = function() {return this.gender;};
}
// when the function is called with the new keyword "this" is returned instead of false
// instantiate a Person object named cody
var cody = new Person(true, 33, 'male');
// cody is an object and an instance of Person()
console.log(typeof cody); // logs object
console.log(cody); // logs the internal properties and values of cody
console.log(cody.constructor); // logs the Person() function
最新文章
- Ubuntu Dev Box Setup
- CSS深入研究:display的恐怖故事解密(2) - table-cell
- 【洛谷P2889】Milking Time
- jQuery学习笔记---兄弟元素、子元素和父元素的获取
- mongoose的promise(转发)
- 2014-2015 ACM-ICPC, Asia Xian Regional Contest G The Problem to Slow Down You 回文树
- 浅谈MVC模式
- Android studio中添加外部的jar包
- 如何把函数都用promise方式实现?
- win7+ ubuntu 双系统
- c# List实现原理
- C学习笔记(自增)
- IntelliJ IDEA使用SVN检出项目到本地工作空间
- shell脚本一键安装redis
- RestfulAPI超简单入门
- OpenStack云桌面系列【2】—OpenStack和Spice
- python3 线性同余发生器 ( random 随机数生成器 ) 伪随机数产生周期的一些探究
- DLL文件的使用
- WPF进阶之接口(3):INotifyPropertyChanged,ICommand
- openwrt生成的镜像放在哪里
热门文章
- filter-mapping中的dispatcher使用
- windows下使用selenium报错selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH
- ActiveMQ教程(消息发送和接受)
- 决定整理一下canvas的基础学习
- # 2018-2019-2 20165210《网络攻防技术》Exp1 PC平台逆向破解(BOF实验)
- L171
- jenkins执行xctool命令出现command not found问题解决方法
- 在头文件中声明class 类 与 include类所在的头文件区别---理解
- Mac OS 升级到10.12问题 Android ADT 下载SDK问题 https://dl-ssl.google.com refused...
- 你离BAT之间,只差这一套Java面试题