美文网首页
js中享元模式

js中享元模式

作者: 阿凯_8b27 | 来源:发表于2020-11-24 17:14 被阅读0次

享元模式主要是对其数据,方法共享分离,它将数据和方法分成内部数据,内部方法和外部数据。外部方法,内部方法与内部数据指的是相似或者共有的数据和方法
享元动作

var FlyWeight = {
    movex: function(x){
        this.x = x;
    },
    mobeY: function(y){
        this.y = y;
    }
}
var Player = function(x,y,c){
    this.x = x;
    this.y = y;
    this.color = c;
}
Player.prototype = FlyWeight;
Player.prototype.changeC = function(c){
    this.color = c;
}
var Sprit = function(x,y,r) = {
    this.x= x;
    this.y = y;
    this.r = r;
}
Sprit.prototype = FlyWeight;
Sprit.prototype.changeR = function(r){
    this.r = r;
}
var player = new Plyaer(5,6,'red');
player.moveX(6)
var sporit1 = new Sprit(2,3,4)
sporit1.moveX(6)

相关文章

网友评论

      本文标题:js中享元模式

      本文链接:https://www.haomeiwen.com/subject/mxqosktx.html