You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaScript基础对象参数继承机制及Wikitude中onTargetsLoaded来源问询

JavaScript Object 继承与 Wikitude 中 onTargetsLoaded 的疑问解答

一、JavaScript 基础 Object 对象的继承逻辑

Great questions! Let's start with the Object inheritance part.

In JavaScript, every plain object you create (like {} or new Object()) inherits built-in properties and methods from Object.prototype via the prototype chain. That's why all objects have access to things like toString(), hasOwnProperty(), or valueOf()—those are baked into the base Object prototype.

When you mention "inheriting parameters," I think you might be mixing up two scenarios:

  • If you're talking about initializing an Object with a value (like new Object("test")), this just creates a wrapper object for the primitive value, and it still inherits from Object.prototype like any other object.
  • If you mean how one object inherits custom properties from another, that's prototype inheritance (not directly tied to the base Object itself). For example, const childObj = Object.create(parentObj) makes childObj's prototype point to parentObj, letting it access parentObj's properties—while parentObj still inherits from Object.prototype further up the chain.

二、Wikitude 中 onTargetsLoaded 的来源解析

Now onto your Wikitude code confusion—this is a super common pattern in JS libraries, so let's break it down.

The onTargetsLoaded property has nothing to do with inheriting from Object. Instead, it's a custom property you (or the code you're looking at) define in a plain object that gets passed to a Wikitude API method. Here's the breakdown:

Wikitude's AR SDK uses an "options object" pattern. When you call certain SDK methods (like one that loads image targets), you pass a plain object with pre-agreed properties—onTargetsLoaded is one of these agreed-upon keys. The SDK's internal code checks for this property, and if it's a function, it calls it once the targets finish loading.

Think of this simplified example to get the idea:

// Hypothetical Wikitude SDK method
function loadARTargets(configOptions) {
  // Internal code to load targets from your source...
  // Once loading completes:
  if (typeof configOptions.onTargetsLoaded === 'function') {
    configOptions.onTargetsLoaded(); // Run your custom callback
  }
}

// How you'd call it in your code
loadARTargets({
  onTargetsLoaded: function() {
    console.log('All AR targets loaded successfully!');
  },
  // Other optional config properties the SDK expects...
});

Key clarifications here:

  • That plain object doesn't "inherit" onTargetsLoaded—you're explicitly adding it as a custom property. JavaScript lets you attach any property to plain objects, no inheritance required.
  • You mentioned thinking this parameter "only exists in AR plugin classes"—that's a misunderstanding. Wikitude doesn't force you to inherit from a class with this property; instead, it just expects you to pass an object that includes this callback (if you want to handle the loaded event). It's an API convention, not an inherited class property.

内容的提问来源于stack exchange,提问作者user3355139

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:38:49