関数オブジェクトには、名前と呼ばれる非標準のプロパティがあります。誰かがそれを変更する方法を知っていますか? または、匿名関数の名前を変更する他の方法はありますか? JavaScript が動的に名前を付けた変数を作成できればよいのですが、パブリック オブジェクトのプロパティ name しか作成できないようです。
私は何をしようとしていますか?
私はこのような何かを達成しようとしています。
// o - literal object, or json
// c - string
function givemeConstructor(o, c, a}){
var a = a || 'Object';
// check other variables
var cons;
if(a === 'Object'){
cons = function(){};
for(p in o) cons.prototype[p] = o[p];
cons.name = c;
}
else{
// a way to create a constructor that inherits from a
// adds object as new prototype
}
return cons;
}
var cons = givemeConstructor({x:1,y:1, toString:function(){return '['+ x + ','+ y+'']'}, 'Point'})
最終的に内省可能なオブジェクトを取得します。