面向对象编程js

几种模块化js编程demo


var module1 = new Object({

_count:1,

m1:function(){

console.log("m1 method start...");

},

m2:function(){

console.log("m2 method start...");

}

});

module1.m1();

console.log(module1._count);


var module2 = (function(){

var _count=3;

var m1 = function(){

console.log(_count);

console.log("module2 m1 method start...");

};

var m2 = function(){

console.log("module2 m2 method start...");

};

return {

m1:m1,

m2:m2

};

})();

console.log(module2.m1);

module2.m1();

console.log(module2._count);



function Spinning(name){

this.name = name;

console.log("start init ...");

}

Spinning.prototype.run = function(){

console.log(this.name+"Spinning init ...");

}

var a = new Spinning("zmf");

a.run();


执行结果:

面向对象编程js_第1张图片



你可能感兴趣的:(面向对象编程js)