summaryrefslogtreecommitdiffstats
path: root/prototype-this-new.js
blob: 96033f440907b496b43e87801666dfeb2301c65c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// these are the same, former invokes constructor function
new function() {
    console.log('foo');
};
(function(){
    console.log('bar');
})();
// both functions are unnamed, so there's our only chance to invoke them
// 'new' implies blank object context, e.g. to make instances

function polygon() {
    this.sides = 4;
    this.side_length = 4;
}

var polygonp = function() {};
polygonp.prototype.perimeter = function() {
    polygonp.sides * length_side;
}

// with new always include (), even when there are no args
var square1 = new polygon();
var square2 = polygon;
var square3 = polygon();