alert(123); // 顯示123 |
console.log(a); // 在控制台顯示 a 變量內容 |
class People def initialize(name, age) @name = name @age = age end end |
function People(name, age) { this.name = name; this.age = age; } |
var people = new People('你老媽', 17); |
function People(name, age){ name : name, age : age } |
people.name ; 或 people['name'] ; |
var a = new Object(); 或 var a = {}; |
a.name = '你老媽'; a.age = 17; 或 a['name'] = '你老媽'; a['age'] = 17; |
a.123 = 'gg'; // 出錯 a['123'] = 'gg'; // 沒事,但注意如果 a 物件是數組會視作 a[123],數組的屬性就是每個index |
function People(name, age){ this.name = name || '你老媽'; this.age = age || 17; } |
// 假設已有A、B、C三個Sprite對象 A.addChild(C); A.children; // => [Sprite(C對象)] B.addChild(C); A.children; // => [] |
A = new Sprite; B = new Sprite; C = new Sprite; D = new Sprite; E = new Sprite; A.addChild(B); // B > A A.addChild(D); // D > B內所有child B.addChild(C); // C > B B.addChild(E); // E > C 優先度為:D > E > C > B > A |
document.write('<img src='根目錄下的圖片路徑'>'); |
window.onload = function() { SceneManager.run(Scene_Boot); }; |
this.requestUpdate(); |
requestAnimationFrame(this.update.bind(this)); |
this.updateMain(); |
this.requestUpdate(); |
var a = 0; SceneManager.requestUpdate = function() { // 取得和上次執行的時間差 console.log(Date.now() - a); if (!this._stopped) { requestAnimationFrame(this.update.bind(this)); } // 記錄目前時間 a = Date.now(); }; |
for (var 屬性名 in 物件){ (內容) } |
for (var 屬性名 in 物件){ 物件[屬性名] = xxx; ... } |
Object.defineProperty(物件, 屬性名, 特性描述) |
enumerable:允許列舉 (false / true) configurable:允許修改特性 (false / true) |
Object.defineProperty(ConfigManager, 'bgmVolume', { get: function() { return AudioManager._bgmVolume; }, set: function(value) { AudioManager.bgmVolume = value; }, configurable: true // 允許修改特性 //但是,此屬性不會出現在列舉結果 }); |
Object.defineProperty(ConfigManager, 'bgmVolume', { get: function() { return AudioManager._bgmVolume; }, set: function(value) { AudioManager.bgmVolume = value; }, configurable: true, // 允許修改特性 enumerable: true // 可被列舉 }); |
// 來自 http://uupaa.hatenablog.com/entry/2012/11/07/143947 的範例 Object.prototype.myMethod = function() { console.log("myMethod"); }; // 汚染 function eachObject(obj) { for (key in obj) { console.log(key); } } function eachArray(ary) { for (key in ary) { console.log(key); } } eachObject({ a: 1, b: 2 }); // "myMethod", "a", "b" eachArray([ 1, 2, 3 ]); // "myMethod", "0", "1", "2" |
arr = [1,2,3] // 返回 [1,2,3] |
for (var i in arr){ if (!count) {var count = 0;} count += arr[i]; } // => ...? |
for (var i = 0; i < arr.length; i++){ if (!count) {var count = 0;} count += arr[i]; } // => 6 |
for (var i in arr){ if (!count) {var count = 0;} if (arr.hasOwnProperty(i)) {count += arr[i];} } // => 6 |
var 匹配結果 = 正則.exec(被匹配的字串) |
var result = /a(b+)cc\d/.exec('aabbcc123')[0]; // => abbcc1 |
對象.constructor // 但如果是匿名函式只會看到內容不會看到名稱 |
對象 instanceof 建構式 對象.is() |
屬性名 in 對象 or 對象.hasOwnProperty(屬性名) // <= 繼承的、或使用prototype定義的屬性也返回false |
Object.keys() |
函式.caller |
undefined、null、false(廢話)、NaN、0、空字串(''或"") |
// 原式代入一個變量 var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; // 再定義 Game_Interpreter.prototype.pluginCommand = function(command, args) { (追加內容) _Game_Interpreter_pluginCommand.call(this, command, args); // 呼叫原式 (追加內容) }; |
// 建構式定義 function Window_Selectable() { this.initialize.apply(this, arguments); } // 繼承 Window_Selectable.prototype = Object.create(Window_Base.prototype); Window_Selectable.prototype.constructor = Window_Selectable; // 擴充initialize Window_Selectable.prototype.initialize = function(x, y, width, height) { Window_Base.prototype.initialize.call(this, x, y, width, height); (Window_Selectable要用的其他內容) }; |
A B |
// 調用本對象的 _onKeyDown 方法 // bind 查了一下是確保調用對象(這寫在 Input 的方法內,所以是確保 this 為 Input) document.addEventListener('keydown', this._onKeyDown.bind(this)); |
留言共 3 篇留言
前一篇:[RMVA] 題材拉霸機... 後一篇:[RMMV] 1.1.0...