ES5中prototype的应用

时间:2019-09-12 14:47:56 类型:JS/JQUERY
字号:    

ES5中prototype的应用, 在JS中,函数同时也是一个对象, 向这个函数对象中添加属性及函数可使用prototype这个属性


<script type="text/javascript">
		function Obj(){
			this.name ="南昌雅腾";
			this.success = function(){
						console.log('成功');
					}
		}
		Obj.prototype.address = "南昌艾溪湖边上";
		Obj.prototype.getName = function(){
			return this.name;
		}

		var app = new Obj();
		console.log(app.getName());
	</script>