---
title: "组合使用构造函数模式和原型模式"
author: "MaxOmnis"
date: "2014-11-23T14:48:39Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2014-11-23T14:48:39Z"
id: 2159451
url: "https://maxomnis.iteye.com/blog/2159451"
---

function testPrototype2(){

 

    function Person3(name, age, job){

        this.name=name;

        this.age=age;

        this.job=job;

        this.friends =\["shelb", "court"];

    }

 

    Person3.prototype = {

        constructor:Person3,

        sayName:function(){

            alert(this.name);

        }

    }

 

    var person1 = new Person3("jack",10,"it");

    var person2 = new Person3("karry",1,"woker");

 

 

    person1.friends.push("tom");

    console.info(person1.friends);

    console.info(person2.friends);

 

    console.info(person1.friends==person2.friends);

    console.info(person1.sayName == person2.sayName);

}