admin管理员组

文章数量:1289583

I came across this looking at the source for some physics animations in JavaScript found here on github where he's written this

if (this._position < 0) this._position /= 3;

A quick Google yielded nothing, anyone know?

I came across this looking at the source for some physics animations in JavaScript found here on github where he's written this

if (this._position < 0) this._position /= 3;

A quick Google yielded nothing, anyone know?

Share Improve this question edited Feb 13, 2016 at 13:43 Tushar 87.2k21 gold badges163 silver badges181 bronze badges asked Feb 13, 2016 at 13:37 bigmadwolfbigmadwolf 3,5393 gold badges31 silver badges47 bronze badges 3
  • 2 Shorthand division operator. – Tushar Commented Feb 13, 2016 at 13:37
  • 2 Called a 'Division/Assignment Operator': It does a divide then assigns the value. Details here: developer.mozilla/en-US/docs/Web/JavaScript/Guide/… – Jeremy J Starcher Commented Feb 13, 2016 at 13:38
  • so this means "if the position is less than zero, make position equal to position divided by three"...? – bigmadwolf Commented Feb 13, 2016 at 13:39
Add a ment  | 

3 Answers 3

Reset to default 11

The operator is shorthand division operator. It is equivalent to

this.position = this.position / 3;

The division will be performed first and then the result will be assigned to the dividend.

Quoting from MDN

The division assignment operator divides a variable by the value of the right operand and assigns the result to the variable.

It's the division equivalent of += or -=

This is a division asignment operator: This performs the following operation: Ex:

var x=10,y=2;
x=x/y;
/*
which is equivalent to x/=y;
and returns 5
*/

本文标签: What does 3939 operator mean in JavaScriptStack Overflow