首页 > 代码库 > 原型插件 prototype

原型插件 prototype

function Person(opts) {  var def = {    name: ‘何XX‘,    age: 10,    sex: ‘男‘  };  opts = $.extend(def,opts);  this.name = opts.name;  this.age = opts.age;  this.sex = opts.sex;}Person.prototype.output= function () {  console.log(this.name);};


//调用方法1:
var tom = new Person({  name: "大叔",  age: 2009,  sex: ‘女‘});
tom.output();

//调用方法2:
var o = new Object();
Car.call(o, "Dudu", 2010, 5000);
console.log(o.output());

 

 

 

原型插件 prototype