Al Ameen
Al Ameen

Reputation: 372

TypeError: 'set' on proxy: trap returned falsish for property

I changed my code from es5 class prototype representation to es6 class representation. But I am getting error

this is the code before and after migration to es6

es5 syntax

function RoutingScreen (context) {
  Object.assign(this, {route} = context)
}

RoutingScreen.prototype.onEnter = function(state) {
  state.scaning = false
  state.status = 'Scan to continue'
  curState = states.init
};

es6 syntax

class RoutingScreen{
  constructor(context){
    Object.assign(this, {route}= context)
  }

onEnter(state){
    state.scaning = false
    state.status = 'Scan to continue'
    curState = states.init
  }
}

I am getting error like this

TypeError: 'set' on proxy: trap returned falsish for property 'scaning'

but es5 code is working properly.

I am using node version 8.1

I don't know what i had done wrong here.

this where i called these method

    function setRoute (newRoute) {
        var r = currentRoute()
        console.log('changeRoute from ' + (r?r.route:'""') + ' to ' + newRoute)
        if (r && r.route == newRoute) {
          return true
        }
        if (!r || !r.onExit || r.onExit(state) !== false) {
          stateStack.pop()
        }
        r = newRoute ? pushRoute(newRoute) : currentRoute()
        state.session.route = r.route


        return !r.onEnter || r.onEnter(state)

  }

Upvotes: 10

Views: 14362

Answers (1)

MC Hammerabi
MC Hammerabi

Reputation: 471

I was having this same issue in an example of using proxy objects I was going through the JavaScript Ninja book ... when I attempted to write a set method.

set: (target, key, value) => {
  target[key] = value;
}

This throws a TypeError in strict mode:

Uncaught TypeError: 'set' on proxy: trap returned falsish for property

Since it was returning 'falsish', I fixed it by returning true with the method:

set: (target, key, value) => {
  target[key] = value;
  return true;
}

Upvotes: 15

Related Questions