別のファイルからオブジェクトを呼び出すときに問題に直面しています。
function node(id, content, prev, next){
this.id = id;
this.prev = prev;
this.next = next;
this.content = content;
}
オブジェクトが以前に定義されていない場合に備えて、このコードを使用して外部ファイルをロードしています。
function callNode(node){
if(typeof(node) === 'undefined')
{
path = "js/tree/t2.js";
$.getScript(path, function(){
console.log('done');
for(i in node)
alert(node[i]);
});
}
else alert('node exist');
}
t2.js には次のものがあります。
n1 = new node('text1','n1');
n2 = new node('text2','n2');
n3 = new node('text3','n3');
n2.next = n3;
n2.prev = n1;
HTMLコード:
<button onclick="callNode(n2)"..
しかし、それは私に未定義のオブジェクトを与え続けます