在JS或OOP语言中,多态是通过创建不同的类型来创建的。
例如:
class Field {...}
class DropdownField extends Field {
getValue() {
//implementation ....
}
}
假设我有一个包含一些方法的库forms.js:
class Forms {
getFieldsValues() {
let values = [];
for (let f of this.fields) {
values.push(f.getValue());
我正在使用redux创建一个应用程序。我用的是打字稿和immutable.js。当我对类型化对象使用不可变的方法(如updateIn() )时,它会抛出错误。
以下是我尝试过的代码:
interface aType{
id: number
}
function randFun(a:aType){
a = a.updateIn([....]); //It is throwing error in this line of code.
}
randFun({id:2});
属性'updateIn‘不存在于{.}类型中。
我怎样才能消除这个错误?
我想创建一个Javascript/JQuery对象,它包含许多函数,可以通过HTMl页面访问,但是我经常遇到错误。下面是我的外部JS文件
function AppPage(settings){
function save(formid){
//get form data and save
};
function delete(rowid){
//get rowid and delete via ajax
}
}
现在我想初始化Javascript对象,并使它在整个过程中都是可访问的。
<!DOCTYPE html&g
我在node.js中有一个构造函数,如下所示。
function Tree() {
//Redirect to other functions depends upon argument count.
}
我创建了这样的对象
var theTree = new Tree('Redwood');
var theTree = new Tree('Redwood',5);
var theTree = new Tree('Redwood',10,"USA");
我的要求是,我想重定向到不同的函数,具体取决于构造函数的参数数。我怎样才能
我正在创建一个带有高速公路的web应用程序。
我想将应用程序从callingScript运行到module的端口传递给
callingScript.js
const http = require('http');
const app = require('./module');
const port = process.env.PORT || 3000;
app.set('port', port);
const server = http.createServer(app);
// it serves to the correct por
我使用下面的代码在Chart.js中设置全局选项
Chart.defaults.global = {
animationSteps: 30,
tooltipCornerRadius: 0
}
var ctx = document.getElementById("canvas").getContext("2d");
var LChart = new Chart(ctx).Line(data, {
});
然而,它给了我错误。
TypeError: fn is not a function
在Chart.js中的第499行
我怎样才能解决这