无法将类作为函数调用及crossconnection模型计算属性问题咨询
Hey Joe, let's tackle your two technical issues step by step:
This error almost always pops up when you try to instantiate an ES6 class without using the new keyword. Here’s what to check:
- Double-check where you’re creating instances of your class. For example, if you have a class like:
Wrong usage (throws the error):class MyClass { constructor() { /* ... */ } }
Correct usage:const instance = MyClass(); // Missing `new`const instance = new MyClass(); - If you’re using a framework like Ember (since you mentioned computed properties), make sure you’re not invoking a component or model class directly without the framework’s built-in instantiation methods. For example, Ember models are usually fetched via
store.findRecord()instead of manually callingnew Model(). - Rarely, syntax errors in your class code (like missing curly braces in the class body) can make the JS engine misinterpret it as a regular function instead of a class—double-check your class definition for typos.
crossconnection Model Looking at your relevantPoints code, there are a few key issues causing the异常:
1. Missing Dependent Keys
Ember’s computed properties need explicit dependent keys to know when to recalculate their value. Your current code doesn’t list IsCA or IsCM as dependencies, so the property won’t update when those values change. Fix this by adding the keys to the computed() call:
relevantPoints: computed('IsCA', 'IsCM', function () { // ... your existing logic here })
2. Incomplete Return Value in Third Branch
Your third else if returns "/assets/images/..."—an incomplete path that will lead to broken image URLs or unexpected behavior. Replace it with a full valid path, e.g.:
else if (this.get('IsCA') === false && this.get('IsCM') === true) { return "/assets/images/big/cm.png"; // Example full path }
3. Missing Default Else Branch
If neither IsCA nor IsCM is true, your function will return undefined, which can cause errors when using relevantPoints (like rendering an image). Add a default case to handle this scenario:
else { // Return a default image path or appropriate fallback value return "/assets/images/big/default.png"; }
Bonus Check: Verify Property Types
Make sure IsCA and IsCM are actual boolean values (true/false) and not string values ("true"/"false"). If they’re strings, your strict equality checks (=== true) will fail. Adjust the checks if needed:
const isCA = this.get('IsCA') === true || this.get('IsCA') === "true"; const isCM = this.get('IsCM') === true || this.get('IsCM') === "true"; if (isCA && isCM) { /* ... */ }
内容的提问来源于stack exchange,提问作者Joe25

