[]js继承模式


1.png


2.png


3.png


4.png

 
 
new function() {
var className = 'BackGround';
window[className] = (function() {
Laya.class(Class, className, Laya.Sprite);

function Class() {
Class.super(this);

// this定义..

this.init();
}
Class.prototype.init = function() {
console.log(this);
};

return Class;
})();
}




var __extends = (this && this.__extends) || function(d, b) {
for (var p in b) {
(b.hasOwnProperty(p)) && (d[p] = b[p]);
}
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};

var BackGround = (function() {
__extends(Class, Laya.Sprite);

function Class() {
Laya.Sprite.call(this);
this.img = [];
this.init();
}
Class.prototype.init = function() {
Laya.stage.addChild(this);
this.bg();
Laya.timer.frameLoop(1, this, this.loop);
};
Class.prototype.bg = function() {
for (var i = 0; i < 2; i++) {
this.img[i] = new Laya.Image('background.png');
this.addChild(this.img[i]);
}
this.img[0].y = 0;
this.img[1].y = -852;
}
Class.prototype.loop = function() {
for (var i = 0; i < this.img.length; i++) {
this.img[i].y += 1;
if (this.img[i].y >= 852) {
this.img[i].y = -852;
}
}
};
return Class;
}());


new function() {
var className = 'BackGround';
window[className] = (function() {
Laya.class(Class, className, Laya.Sprite);

function Class() {
Class.super(this);

this.img = [];

this.init();
}
Class.prototype.init = function() {
Laya.stage.addChild(this);
this.bg();
Laya.timer.frameLoop(1, this, this.loop);
};
Class.prototype.bg = function() {
for (var i = 0; i < 2; i++) {
this.img[i] = new Laya.Image('background.png');
this.addChild(this.img[i]);
}
this.img[0].y = 0;
this.img[1].y = -852;
}
Class.prototype.loop = function() {
for (var i = 0; i < this.img.length; i++) {
this.img[i].y += 1;
if (this.img[i].y >= 852) {
this.img[i].y = -852;
}
}
};
return Class;
})();
}




Laya.init(400, 852, Laya.WebGL);


// new BackGround();
new BackGround();

已邀请:

cuixueying

赞同来自:

你想表达什么呢?是出什么问题了吗,麻烦详细描述下吧!

要回复问题请先

商务合作
商务合作