gpt4 book ai didi

javascript - 什么是 Class.extend({});下面的javascript代码中的代码?

转载 作者:行者123 更新时间:2023-11-28 00:40:55 24 4
gpt4 key购买 nike

我不明白下面的代码。什么是 Class.extend() 以及它的作用是什么?它来自 Udacity 上的 HTML 开发图集加载教程。

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;
........

其余的都是微不足道的。

最佳答案

结果 Class 对象是在 core.js 中定义的,它是 Udacity 上工作文件旁边的另一个文件。

该代码可能基于 John Resig 的博客文章 Simple JavaScript Inheritance 。它是一种在 Javascript 中实现“经典”(或“面向对象,而不是“基于原型(prototype)”)继承的简单、可重用的方法。

关于javascript - 什么是 Class.extend({});下面的javascript代码中的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27942277/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com