Skip to content

var a = 1; 如何让 a == a.value; #10

Open

Description

@CodeRookie262

var a = 1; 如何让 a == a.value;

var a = 1;

//code

console.log(a == a.value); // true

Activity

  1. CodeRookie262 commented on Dec 29, 2020

    @CodeRookie262
    OwnerAuthor

    var a = 1; 如何让 a == a.value;

    var a = 1;
    
    //code
    
    console.log(a == a.value); // true

    解法:

    因为 a属于Number类型,所以我们可以考虑从Number.prototype` 入手

    var a = 1;
    Object.defineProperty(Number.prototype,"value",{
        get(){
            return this;
        }
    })
    
    console.log(a == a.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions