你好.我是面向对象的JavaScript新手,我无法弄清楚什么是接口节点?下面是我的代码,错误是打开的line 96.
这个错误可能是什么原因以及如何解决?
window.onload=initAll;
////////////////////////////////////////////////////////////////////
var msg_dialog=new DialogBox();
var send_msg_but=new Button();
////////////////////////////////////////////////////////////////////
msg_dialog.tit="New Message";
msg_dialog.bod="The Message Body Shall Reside Here";
msg_dialog.fot=send_msg_but;
////////////////////////////////////////////////////////////////////
send_msg_but.label="Send";
send_msg_but.action=msg_dialog.done();
////////////////////////////////////////////////////////////////////
function initAll(){
getDef();
}
function $(x){
return document.getElementById(x);
}
function _(x){
return document.createElement(x);
}
function getDef(){
var xhr;
var url="json/def.json";
if(window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}
else{
xhr=new ActiveXObject("Microsoft:XMLHTTP");
}
xhr.open("GET", url);
xhr.onreadystatechange=function(){
//creating the buffer div here creates 3 instances of the same object because the state changes from 0 (initial) to 1, 2 …Run Code Online (Sandbox Code Playgroud) 对我来说似乎很直观,但事实证明事情并不是这样的!目标是删除传递的元素(如果存在)并返回其余元素。我知道有很多方法可以实现这一目标 - 包括filter:const rest = selection.filter(i => i !== item)- 但是,正如我所说,我认为这种方法会是一件事 - 因为它是为了objects/key:value pairs.
if (selection.includes(item)) {
// remove if available
const [item, ...rest] = selection;
setSelection(rest)
} else {
// ...
}
Run Code Online (Sandbox Code Playgroud)
工作方式是将的元素destructuring分配给 item 并将其余项目分配给- 一个数组。这是正确的——至少从我的理解来看,事情就是这样运作的。firstselectionrest
是否可以使用解构赋值从数组中提取特定项目并将其余元素解压到变量中?
我将Redux重构为我的代码,但无法弄清楚如何获得以前的状态.我需要这个状态用于我的componentDidUpdate生命周期方法,以便我可以调用其他方法而不会陷入无限循环.
// when component re-renders
componentDidUpdate(prevState) {
// if the current page changes, or the search term changes.
if(prevState.currentPage !== this.props.bucketlistState.currentPage ||
prevState.searchTerm !== this.props.bucketlistState.searchTerm) {
this.getBucketlists();
}
}
Run Code Online (Sandbox Code Playgroud)