添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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)
                Can you show the code for set method for scanning on the state Object ? What are you returning from it ?
– Malice
                Aug 22, 2017 at 7:08
                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)   }  state is global state object that is changing in onEnter method
– Al Ameen
                Aug 22, 2017 at 7:15
                You've to put the above code between backticks for readability , it's just left to key 1 on your keyboard
– Malice
                Aug 22, 2017 at 7:16

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;
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.