Rami Awar
Rami Awar

Reputation: 750

What is the Class.extend({}); code in the following javascript code?

I don't understand the following code. What is the Class.extend() and what does it do? It's from an HTML development atlas loading tutorial on Udacity.

var gSpriteSheets = {};

//-----------------------------------------
SpriteSheetClass = Class.extend({

// We store in the SpriteSheetClass:
//
// The Image object that we created for our
// atlas.
img: null,

// The URL path that we grabbed our atlas
// from.
url: "",

// An array of all the sprites in our atlas.
sprites: [],

//-----------------------------------------
init: function () {},

//-----------------------------------------
// Load the atlas at the path 'imgName' into
// memory. This is similar to how we've
// loaded images in previous units.
load: function (imgName) {
    // Store the URL of the spritesheet we want.
    this.url = imgName;
........

The rest is insignificant.

Upvotes: 3

Views: 1096

Answers (1)

Rami Awar
Rami Awar

Reputation: 750

Turns out the Class object is defined in the core.js, another file alongside the working file on Udacity.

The code is probably based on a blog post by John Resig, Simple JavaScript Inheritance. It is a simple, re-usable way to implement "classical" (or "object-oriented, as opposed to "prototype-based") inheritance in Javascript.

Upvotes: 1

Related Questions