[英]Object property behavior is strange
我的代碼:
const w = new Window({ title: "Game Engine", width: 240, height: 160, scale: 3, }) const obj1 = new GameObject({ ctx: w.ctx, name: "Player", width: 16, height: 32, color: "blue", x: 0, y: 0, }) w.init() console.log(w) console.log(obj1)
控制台 Output:
為什么 obj1 沒有從 w 獲取 ctx? 從第一個日志,我可以了解到 w object 有一個 ctx 屬性。 所以如果我想要這個 ctx 我必須寫w.ctx
(就像我在我的 obj1 的定義中所做的那樣),但它不起作用
據推測,在您調用init
方法之前, obj1
沒有ctx
屬性(並且在您復制了ctx
屬性的前一個undefined
值之后才這樣做)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.