Giter Club home page Giter Club logo

Comments (7)

chrisvfritz avatar chrisvfritz commented on May 20, 2024 315

@CaptainYouz This happens because the ES6/2015 arrow function syntax (() => {}) binds this to the parent context. In this case, the parent context is the module. Since this is undefined in the module context, that undefined value is passed to each of the lifecycle methods instead of the view model as you'd expect.

To fix this, you'll need to use a normal function declaration:

created: function () {
  console.log('created', this);
},

Or, my personal preference is the ES6/2015 shorthand, which does the same as above:

created () {
  console.log('created', this);
},

from browserify-simple.

chrisvfritz avatar chrisvfritz commented on May 20, 2024 8

@theluk You don't need to do anything special. Just wrapping the function with debounce should work, e.g.:

myMethod: debounce(
  function () {
    // `this` is the app/component instance here
  },
  500
)

from browserify-simple.

CaptainYouz avatar CaptainYouz commented on May 20, 2024 1

Thanks for the explanation !
It's working now ๐Ÿ‘ .

from browserify-simple.

jgb-solutions avatar jgb-solutions commented on May 20, 2024

great!

from browserify-simple.

taoliujun avatar taoliujun commented on May 20, 2024

but this is still link methods.but not vm.

from browserify-simple.

imageslr avatar imageslr commented on May 20, 2024

Thanks a lot!!!

from browserify-simple.

theluk avatar theluk commented on May 20, 2024

how are you dealing with methods you need to bind to this. for example when you want to wrap a method in lodashยดs debounce?

from browserify-simple.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.