javascript - Best Way to Create an "instance" in JS -
lately, on number of js game making blogs , sites etc. have seen new convention creating kind of "instance". looks this:
var newcharacter = function (x, y) { homecoming { x: x, y: y, width: 50, height: 50, update: function () { //do update stuff here } }; }; var mycharacter = newcharacter(20, 30); //create "instance"
as opposed the traditional way:
var character = function (x, y) { this.x = x; this.y = y; this.width = 50; this.height = 50; this.update = function () { //do update stuff here }; }; var mycharacter = new character(20, 30); //create intance
i curious advantage of using first way might be. more efficent, semantic, or faster?
javascript oop
No comments:
Post a Comment