View Full Version : Ext.type returns "object" for a function

14 Apr 2011, 8:01 AM
I have an object that I have created, below is a skeleton of what it looks like. It has basic properties and such and also has some functions that perform certain operations, i.e. validate method that validates the properties are correct.

person = function(config) {
Ext.apply(this, config);

person.prototype = {
Name: '',

age: 0,

address: '',

phoneNumbers: [],

validate: function() {
// do some validation to make sure properties have correct value

I need to find a way to strip off the methods though because when I try to send it through serialization it chokes on the methods. I'm using a ASP.Net ScriptManager to call an asmx service. I'm also using popup windows. If i try to call the parent window to make a call to the webservice I get a error saying "Sys.InvalidOperationException: Cannot serialize object with cyclic reference within child properties.". I've spent many hours chasing this error through Google and haven't found any help. The strange thing is if I make the call from the parent window it works fine.

Anyways I thought since its bombing during serialization on the validate method that I would strip off any methods and send just the raw object with its properties. To do this I wrote something like code below

var serverParam = {};
for(var ele in obj) {
if(!Ext.isFunction(obj[ele])) {
// assign to obj to send to server
serverParam[ele] = obj[ele];

I've also tried Ext.decode(Ext.encode(obj)) which does help but it looses some of the properties and also leads me down a different rabbit trail of errors on the server side.

My question here is regarding the problem of using Ext.isFunction on the "validate" method I gave in my example above it still gets added. When I call Ext.type and pass it obj[ele] it returns "object", I thought I would get "object function".

Does anyone have any ideas how I can accurately test for a function and/or how I can take an object and make a copy of it excluding all methods? It also bombs on the array methods (i.e. indexOf).

Thanks for any insight.

20 Apr 2011, 5:39 AM
After much digging I've found the root cause of the problem is due to if an object is not created in the same window and you try to use Ext.type or Ext.isFunction it will always return object. I've had to take other measure of checking for this by looking at the constructor.__typeName and the prototype. The problem only occurs when using popup windows. I've written some code now that gets me what I need. Any idea if anything in the Ext toolbox in the future that would handle objects passed from child windows?