Jump to content

readable arguments


bexphones
 Share

Recommended Posts

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

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);

 

Link to comment
Share on other sites

  • 2 weeks later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...