[READ-ONLY] Mirror of https://github.com/probablykasper/playground.
playground.kasper.space
662 B
40 lines
1"use strict"
2//create object
3var player1 = {
4 name: "Fred",
5 score: 10000,
6 rank: 1,
7};
8// add property
9player1.gameType = "MMORPG";
10// add method
11player1.logScore = function() {
12 console.log(this.score)
13};
14//call method
15player1.logScore();
16
17
18
19function Player(n,s,r) {
20 this.name = n;
21 this.score = s;
22 this.rank = r;
23}
24
25Player.prototype.logInfo = function() {
26 console.log("I am" , this.name);
27}
28
29Player.prototype.promote = function() {
30 this.rank++;
31 console.log("player " + this.name + " promoted to rank " + this.rank);
32}
33
34var fred = new Player("Fred",1000,2);
35fred.logInfo();
36fred.promote();
37
38var bob = new Player("Bob",50,1);
39bob.logInfo();
40bob.promote();