Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
What they don't tell you about JavaScript
1. /**
* southWest
* Gets the southwestern quadrant of the tree
* return {Quadtree}
**/
Quadtree.prototype.southWest = function() {
return new Quadtree(
new space2d.Point(
this._origin.x,
Math.floor(this._size.y / 2)
),
new space2d.Point(
Math.floor(this._size.x / 2),
this._size.y
),
this
);
};
/**
* southEast
* Gets the southeastern quadrant of the tree
* return {Quadtree}
**/
Quadtree.prototype.southEast = function() {
return new Quadtree(
new space2d.Point(
Math.floor(this._size.x / 2),
Math.floor(this._size.y / 2)
),
new space2d.Point(
this._size.x,
this._size.y
),
this
);
};
JavaScript
What they don’t tell you about
Raphael Cruzeiro
http://raphaelcruzeiro.com
@rcdeveloper
Wednesday, July 10, 13
15. When declaring variables on
the global scope you make
your code more susceptible to
name clashes.
Wednesday, July 10, 13
16. In JavaScript a function
delimits the scope of
variables
Wednesday, July 10, 13
17. var something = 4;
function foo () {
somethingElse = something + 4;
return somethingElse;
};
foo();
Accidental use of global
variables
Wednesday, July 10, 13
19. var something = 4;
var somethingElse = 7;
function foo () {
console.log(something);
console.log(somethingElse);
var something = “This is confusing.”;
console.log(something);
};
foo();
Wednesday, July 10, 13
20. var something = 4;
var somethingElse = 7;
function foo () {
console.log(something);
console.log(somethingElse);
var something = “This is confusing.”;
console.log(something);
};
foo();
Outputs:
undefined
7
This is confusing.
Wednesday, July 10, 13
23. With a few exceptions:
•Number
•String
•Boolean
•null
•undefined
Wednesday, July 10, 13
24. A side-note about Numbers:
•There is only one type for representing all
numbers.
•It is represented in memory as a 64-bit
floating point
•IEEE-754
> 0.1 + 0.2
0.30000000000000004
Wednesday, July 10, 13
25. Creating an object:
var obj = new Object();
// Or via the object literal
var obj = {};
Wednesday, July 10, 13
33. (function() {
/* Everything that is declared
here is local to this closure only */
})();
Wednesday, July 10, 13
34. You can use closures to emulate
namespaces:
var space = (function(){
var Point = function(x, y) {
if (!(this instanceof Point)) {
return new Point(x, y);
}
this.x = x;
this.y = y;
};
return {
Point: Point
};
})();
Wednesday, July 10, 13
35. You can use closures to emulate
namespaces:
var pt = new space.Point(60, 568);
Wednesday, July 10, 13