0

In an effort to roll off my own object copier for javascript, I want to be able to identify what types each property has. This is my code:

function HandlerFunction(){
}

function item(){
    this.any=1;
    this.doc=document.createElement('DIV');
    this.onclick=new Function('HandlerFunction()');
}

var o={};
o=new item();
o.any.??? = a number indicating 'any' is a custom object name
o.doc.??? = a number indicating doc is an html object name
o.onclick.??? = a number indicating onclick is an even handler name

Is there a function I can use that can replace the question marks that allows me to separate the event handlers, the html elements and custom object names apart from each other so that I don't end up doing recursive copying when iterating through the properties in my future copy function?

Mike -- No longer here
  • 2,064
  • 1
  • 15
  • 37

1 Answers1

0

You can use instanceof for objects and typeof for primitives

o.doc instanceof HTMLElement // true
typeof o.any == "number" // true
o.onclick instanceof Function // true
typeof o.onclick == "function" // true, function also works with typeof

See Which is best to use: typeof or instanceof?

Community
  • 1
  • 1
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217