javasscript创建对象

 

用函数的方法创建一个对象

例:

function MyObject(parameter1, parameter2)

{

        //创建私有属性Private_ Property1

        var Private_ Property1;

        //创建私有属性并初始化

        var Private_ Property2 = parameter1;

        //创建共有属性

        this. Public_Property1;

        //创建共有属性并初始化

        this. Public_ Property2 = parameter2;

        //创建私有方法

        function Private_Function()

{

       return Private_ Property1> Private_ Property2;

}

//创建共有方法

this. Public_Function = Public_Function;

function Public_Function()

{

       return this. Public_Property1< this. Public_Property2;

}

//创建共有方法2

this. Public_Function2 = Public_Function2;

 

}

//共有方法2的具体函数

function Public_Function()

{

              return this. Public_Property1> this. Public_Property2;

}

 

//创建一个对象变量

var oObject1 = new MyObject();

var oObject2 = new MyObject(2,3);

 

//创建对象2继承MyObject

function Object2(…)

{

             

}

Object. prototype = MyObject;

 

你可能感兴趣的:(javasscript创建对象)