0 Comments

 

Just a snippet for converting a function as string to code:

image

 

Code

<!doctype html>
<html>
<head>
    <meta charset=”utf-8″ />
    <meta http-equiv=”x-ua-compatible” content=”ie=edge”>
    <title>Research</title>
    <meta name=”description” content=”A page to quickly spike some code or styling.”>
    <meta name=”viewport” content=”width=device-width, initial-scale=1″>
    <link rel=”icon” href=”data:;base64,iVBORw0KGgo=”>   
    <style>
       
    </style>
</head>
<body>
    <script>
        // Define a function as a string.
        // Don’t forget the “(” and the “)” arround the function.
        // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
        var functionAsString = “(function(a, b){ return a + b; })”;

        // Convert a string containing a function definition to a real function.
        var fn = eval(functionAsString);

        // Execute the created function.
        var result = fn(1, 2);

        // Log result is: 3
        console.log(result);
    </script>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Data flows and good DDD architecture in .NET Core and Entity Framework (EF)

0 Comments

      # Introduction From the blog post at https://medium.com/@jpdeffo/domain-driven-design-ddd-in-microservice-architecture-for-nutshell-19c7c579009a and code at https://github.com/Defcoq/DDD  I have learned how to architect a .NET Core project by using DDD principals. The main thing you will have to realize, when you come from a layered architecture, is that the logical flow of data, does not correspond with the project references in Visual Studio.              # Logical dataflow…

JSON Serialization and Deserialization

0 Comments

Found a good articale on JSON Serialization and Deserialization: http://www.codeproject.com/Articles/272335/JSON-Serialization-and-Deserialization-in-ASP-NET…