javascript - OOP and jQuery: how to init a var with Deferred(); -


This is my javascript code; its goal is for education only. I am studying js, oop and jquery

  function app () {this.deviceReadyDeferred = new $ Idle (); This.init = function () {console.log ("run"); $ .When (this.deviceReadyDeferred) then (this.run); Document.addEventListener ("click", this.onDeviceReady, incorrect); }, // NB: onDeviceReady is a non-parametri event this.onDeviceReady = function () {console.log ("deviceReady"); This.deviceReadyDeferred.resolve (); }, This.run = function () {console.log ("main"); }} App = new app (); App.init ();   

When I click, I get type error

: this.deviceReadyDeferred is undefined

Why?

  • I have not got '$', undefined, so jQuery is running fine.
  • I'm running Win 7 on GE 1.9.1 FF 19.0.2 on Win 7

    How to postpone a JavaScript object? How to init it and reuse it?

    Edit:

    This code is working. All the problem was in the misuse of my this I am a newbie on OP in Java.

      function app () {var self = this; This.deviceReadyDeferred = New $ Idle (); This.init = function () {console.log ("run"); $ .When (self.deviceReadyDeferred) then (self.run); $ (Document) .on ("click", click itself); }, This.onClick = function () {console.log ("deviceReady"); Self.deviceReadyDeferred.resolve (); }, This.run = function () {console.log ("main"); }} App = new app (); App.init ();    

    this.init = function () {console.log ("run "); Var self = this; $ .When (this.deviceReadyDeferred) then (self.run); Document.addEventListener ("click", manually. OnDeviceReady, incorrect); },

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -