最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Find out Object type in JavaScript? - Stack Overflow

programmeradmin0浏览0评论

I am trying to debug some JQuery ajaxSetUp behaviour. I set a timeout value and wish to see it set in the debugger. To do this I need to know what to watch while debugging. To investigate where the timeout is set, I do the following in a firefox console:

var obj = jQuery.ajaxSetup({
    timeout: 120000
});
console.log("obj=" + obj.timeout)

I want to find out what type of object obj is? I know JavaScript is dynamically typed but if I can find out what object it is then I know what to add a watch to when debugging.

I am trying to debug some JQuery ajaxSetUp behaviour. I set a timeout value and wish to see it set in the debugger. To do this I need to know what to watch while debugging. To investigate where the timeout is set, I do the following in a firefox console:

var obj = jQuery.ajaxSetup({
    timeout: 120000
});
console.log("obj=" + obj.timeout)

I want to find out what type of object obj is? I know JavaScript is dynamically typed but if I can find out what object it is then I know what to add a watch to when debugging.

Share Improve this question asked Apr 29, 2013 at 14:03 More Than FiveMore Than Five 10.4k23 gold badges83 silver badges141 bronze badges 1
  • You want to know that obj is really an object from ajax Setup? Not going to happen. – epascarello Commented Apr 29, 2013 at 14:07
Add a ment  | 

5 Answers 5

Reset to default 3

Type of obj is object. See:

typeof obj
// "object"

Also, the constructor is global javascript Object. Here:

obj.constructor.name
// "Object"

jQuery has a few utility methods like .isArray(), .isFunction(), .isNumeric() and .isPlainObject() that return true or false. Use these one after the other to determine whether an object is of a specific type.

there is special function in jquery

jQuery.type(obj)

You can use the typeof operator.

This wasn't a good approach for this problem. I looked at the JQuery source and saw when you invoke ajaxSetUp it updates the jQuery.ajaxSettings object.

So if you do...

console.log(jQuery.ajaxSettings.timeout)

in the debug console you'll get the value.

I am putting answer here in case it is use to anyone.

发布评论

评论列表(0)

  1. 暂无评论