title: Spidermonkey TypeError
body: <p>I've managed to integrate Spidermonkey into my C server side application on Linux.
  Trying to create an object from javascript:</p>
  
  <pre><code>var obj = new MyObject();
  obj.foo()
  </code></pre>
  
  <p>gives the following Error:</p>
  
  <p><strong>[error] test.js:22:TypeError: obj.foo is not a function</strong></p>
  
  <p>I'm probably missing something...Here is how MyObject defined:</p>
  
  <pre><code>//Class definition
  static JSClass myobject_class = {
      "MyObject", JSCLASS_HAS_PRIVATE,
          JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
          JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
          JSCLASS_NO_OPTIONAL_MEMBERS
  };
  
  
  //Methods
  static JSFunctionSpec myobject_funcs[] = {
      JS_FS("foo", JS_foo, 0, 0),
  };
  
  
  //Static methods
  static JSFunctionSpec myobject_funcs_static[] = {
      JS_FS_END
  };
  
  
  
  //foo method
  JSBool JS_foo(JSContext *cx, uintN argc, jsval *vpn) {
  
      return JS_TRUE;
  }
  
  
  //Constructor
  JSBool JS_myobject_ctor(JSContext *cx, uintN argc, jsval *vpn) {
  
      JSObject *obj = JS_NewObjectForConstructor(cx, vpn);
      JS_DefineFunctions(cx,obj,myobject_funcs);
  
  
      return JS_TRUE;
  
  }
  
  //Init context
  JSContext *  context_init(size_t size,void* privateData) {
      /* Create a context. */
      jsContext = JS_NewContext(jsRuntime, 8192);
      if (jsContext == NULL) return NULL;
      .....
      .....
      .....  
      //myobject init
      JSObject *my = JS_InitClass(jsContext, global, NULL, &amp;myobject_class, JS_myobject_ctor, 0, NULL, NULL, NULL, myobject_funcs_static);
      JS_DefineFunctions(jsContext, my, myobject_funcs);
  
      return jsContext;
  
  }
  </code></pre>