---
title: "Disable view code of function javascript"  
description: "Disable view code of function javascript"  
author: "Anonymous User"  
published: 2013-04-04  
updated: 2013-04-04  
canonical: https://www.mindstick.com/forum/707/disable-view-code-of-function-javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Disable view code of function javascript

Hi Everyone!\
Like this, if I made a [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server):\
function a() { [alert](https://answers.mindstick.com/qa/30927/what-is-an-alert)("Hello!") }I don't want you to be able to [view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view) the [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) like:\
[eval](https://www.mindstick.com/forum/2167/inline-coding-one-more-eval-merge)(a)Returns all the code but\
eval(a())Returns the alert\
When doing eval(a) I want it to not return the code, just nothing how?\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Lois!\
Always encapsulate your code in an IIFE (Immediately Invoked Function Expression) so you don't leak variables to the global scope:\
(function(){ function a() { alert("Hello!") } // more stuff...}());\
console.log(eval(a)); //=> Uncaught ReferenceError: a is not defined You can also use a little trick to hide the function code with bind:\
var a = function a() { alert("Hello!")}.bind();\
console.log(eval(a)); //=> function () { [native code] }\
Whenever you think about using eval, think twice, there's probably a better way to do it. If you just want to run the function, just do a(). No need for eval there.\
I hope it resolve your problem!


---

Original Source: https://www.mindstick.com/forum/707/disable-view-code-of-function-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
