bexphones Posted August 1, 2017 Share Posted August 1, 2017 hello everybody, It's my first message on this forum I'm searching to write prototype with readable arguments. I have see this on this page : https://github.com/ryanmcdermott/clean-code-javascript#functions But i have the error : ReferenceError: invalid assignment left-hand side[En savoir plus] what must i do to achieve that ? Thanks a lot. var game = new phaser.game(800, 600, phaser.canvas, 'phaser-test', { preload: preload, create: create, update: update, render: render }); robot = function({game,number,posx,posy,image}){ ///////////////////////////////////////what i would do robot=({ game:game, number:this.number, posx:this.posx, posy:this.posy, image:this.image }) ///////////////////////////////////////what i would do phaser.sprite.call(this,game,this.posx,this.posy,this.image) } robot.prototype=object.create(phaser.sprite.prototype) function preload() { game.load.image('example', 'https://s13.postimg.org/xjhlzmiev/disc_png.png'); } function create() { var e= new robot=({ game:game, number:5, posx:100, posy:200, image:'example' }) game.add.existing(e) console.log(e.number) } function update() { } function render() { } Link to comment Share on other sites More sharing options...
samme Posted August 2, 2017 Share Posted August 2, 2017 Those examples are using the new ES6 syntax. Here is the same: var Robot = function (args) { Phaser.Sprite.call(this, args.game, args.posx, args.posy, args.image, args.frame); delete args.game; // already assigned Object.assign(this, args); }; Robot.prototype = Object.create(Phaser.Sprite.prototype); // … var robotSprite = new Robot({ game: game, number: 5, posx: 100, posy: 200, image: 'example' }); game.add.existing(robotSprite); bexphones 1 Link to comment Share on other sites More sharing options...
bexphones Posted August 10, 2017 Author Share Posted August 10, 2017 Thanks samme and sorry for this delay so now with this technique i could do var config=[arg1,arg2,...] var robots= new Robot(config) i must learn ES6 ! Link to comment Share on other sites More sharing options...
Recommended Posts