Files
json/index.html

63 lines
2.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>json</title>
<style>
html, body {
margin: 0;
padding: 0;
overflow: hidden;
}
body {
height: 100vh;
width: 100vw;
}
</style>
</head>
<body>
<script>
var мир = {};
мир.разобрать = function(словарь) {
for (ключ in словарь)
{
var значение = словарь[ключ];
console.debug("ключ/значение", ключ, значение);
if (значение.startsWith("function"))
{
var содержимое = `мир["${ключ}"] = ` + значение;
мир[ключ] = eval(содержимое);
}
else
{
мир[ключ] = значение;
}
}
};
var json1 = {};
json1.вывести = function(аргумент) {
console.debug('выводим аргумент:', аргумент);
}.toString();
json1.пример = function(аргумент) {
мир.вывести("уга");
console.debug("функция-пример исполнена. аргумент:", аргумент);
}.toString();
json2 = JSON.stringify(json1);
console.debug("2", json2);
var json3 = JSON.parse(json2);
console.debug("3", json3);
мир.разобрать(json3);
console.debug("мир.пример", мир.пример);
мир.пример(123);
мир.вывести(77);
</script>
</body>
</html>