[removed] hiding contents of key

前端 未结 8 1263
梦谈多话
梦谈多话 2020-12-22 14:04

In the code below I want to hide the contents of the key(speaker) key being viewed by browser console.

var App_Version         


        
8条回答
  •  隐瞒了意图╮
    2020-12-22 14:46

    although it's not fully clear from the small code provided, protecting it from the browsers console is straight forward IF we are only talking about someone console.logging the value (as your question seems to hint).

    you can put it inside a closure, something like a revealing/modular pattern:

    var app = (function () {
    
        var Speaker = "something";
        // only available on app declaration as the function is immediately called
        return // some object/function protecting the speaker value
    })();
    
    console.log(Speaker); // gives an error
    console.log(app.Speaker); // gives an error
    

    This of course only stops someone using basic dev tools like console.log, it wont stop someone adding breakpoints. the nature of javascript I'm afraid

提交回复
热议问题