Loading ...
Sorry, an error occurred while loading the content.

RE: [jslint] this question

Expand Messages
  • Rob Richardson
    Try this: var p = 2, o = { p: a }; o.f = (function (m) { return { l: m.p }; }(o)); p = o.f.l; Or this: var p = 2, o = { p: a }; o.prototype.f =
    Message 1 of 22 , Nov 18, 2011
    • 0 Attachment
      Try this:

      var p = 2,
      o = {
      p: "a"
      };
      o.f = (function (m) {
      return {
      l: m.p
      };
      }(o));
      p = o.f.l;

      Or this:

      var p = 2,
      o = {
      p: "a"
      };
      o.prototype.f = function () {
      return {
      l: this.p
      };
      };
      p = o.f.l;

      Rob


      -----Original Message-----
      From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
      Behalf Of Nagy Endre
      Sent: Friday, November 18, 2011 7:13 AM
      To: jslint_com@yahoogroups.com
      Subject: [jslint] this question




      Hi everyone, maybe it's a little offtopic sorry, but can anyone explain why
      "this" inside the "o" object is refer to window ?
      Why it's not refer to the "o" object if we are inside there? I want to
      access from the returned object in function "f" the "o.p" property without
      using "o". Thanks!

      var p = 2,
      o = {
      p: "a",
      f: (function (m) {
      return {
      l: m.p
      };
      }(this))
      };

      p = o.f.l;

      Endre

      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.