markdown JS:创建对象

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown JS:创建对象相关的知识,希望对你有一定的参考价值。

1. Function based
```sh
  function Employee(fName, lName, age, salary){
  	this.firstName = fName;
  	this.lastName = lName;
  	this.age = age;
  	this.salary = salary;
  }

  // Creating multiple object which have similar property but diff value assigned to object property.
  var employee1 = new Employee('John', 'Moto', 24, '5000$');
  var employee1 = new Employee('Ryan', 'Jor', 26, '3000$');
  var employee1 = new Employee('Andre', 'Salt', 26, '4000$');
```

2. Object Literal
```sh
var employee = {
	name : 'Nishant',
	salary : 245678,
	getName : function(){
		return this.name;
	}
}
```
3. From Object using new keyword
```sh
var employee = new Object(); // Created employee object using new keywords and Object()
employee.name = 'Nishant';
employee.getName = function(){
	return this.name;
}
```
4. Using Object.create

以上是关于markdown JS:创建对象的主要内容,如果未能解决你的问题,请参考以下文章

markdown JS字面量与新对象()

markdown JS判断对象是否为空

markdown JS String对象

markdown JS.Objects.For实时编码视频:预定义对象:字符串

markdown 创建js依赖图

markdown JavaScript创建对象