JSON-jQuery-deep copy

Benchmark created by maikudou on


Description

Sometimes one needs to copy a js object without any possible links to other objects

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>

Setup

var personsData = [{
      "first_rus_name": "Нуми",
      "id": 2875,
      "last_rus_name": "Рапас"
    }, {
      "first_rus_name": "Майкл",
      "id": 7,
      "last_rus_name": "Фассбендер"
    }, {
      "first_rus_name": "Шарлиз",
      "id": 1909,
      "last_rus_name": "Терон"
    }, {
      "first_rus_name": "Идрис",
      "id": 931,
      "last_rus_name": "Эльба"
    }, {
      "first_rus_name": "Гай",
      "id": 1132,
      "last_rus_name": "Пирс"
    }, {
      "first_rus_name": "Логан",
      "id": 3700,
      "last_rus_name": "Маршалл-Грин"
    }, {
      "first_rus_name": "Шон",
      "id": 3701,
      "last_rus_name": "Харрис"
    }, {
      "first_rus_name": "Ридли",
      "id": 169,
      "last_rus_name": "Скотт"
    }]
    
    var movie = {
      responseTime: 0,
      responseText: {
        "data": {
          "ambient_light": "movies/841/trailer_background_1.jpg",
          "country": "США",
          "cover": "movies/841/cover_1.jpg",
          "duration": 124,
          "free": false,
          "hd": false,
          "id": 841,
          "images": {
            "big": "/media/cache/d2/5a/d25a1c803063cb44b193a4cc17506a3f.png",
            "medium": "/media/cache/39/a4/39a4bb7ca6c6ecfe6d402b869a64934a.png",
            "small": "/media/cache/c2/8e/c28e1d18af11a7b35f593868c1df5af4.png"
          },
          "interesting_fact": "Имена андроидов в фильмах о Чужих идут в алфавитном порядке: Ash в «Чужом»; Bishop в «Чужих» и «Чужом 3»; Call в «Чужом: Воскрешение». В «Прометее» — David.",
          "is_pwyw": false,
          "lang": "ru",
          "motto": "Через 32 года британский гений Риддли Скотт вновь взялся за мир Чужих",
          "orig_title": "Prometheus",
          "page_background": "movies/841/page_background_3.jpg",
          "persons": {
            "actors": [2875, 7, 1909, 931, 1132, 3700, 3701],
            "directors": [169]
          },
          "personsData": personsData,
          "price": {
            "discounted": "80.00",
            "full": "80.00"
          },
          "ratings": {
            "kinopoisk": "7.5"
          },
          "release_year": 2012,
          "rightsholder": {
            "id": 12,
            "logo_image": "",
            "use_logo": false
          },
          "similar_movies": [814, 749, 807, 382, 383, 614, 713, 748, 110, 153, 83, 112],
          "subtitle": "none",
          "synopsis": "В 2089 году группа археологов, исследуя остров Скай, находит в пещере наскальные рисунки. Там изображены люди, поклоняющиеся высоким гуманоидным существам, указывающим на звёзды. Через десять лет научно-исследовательское судно «Прометей» летит в таинственное место, указанное этими пиктограммами. Андроид Дэвид выводит экипаж судна из анабиоза. «Прометей» совершает посадку. Настало ли время для человечества лицом к лицу встретиться со своими прародителями?",
          "tags": [53, 51, 15, 28, 80, 12, 5, 82, 92],
          "title": "Прометей"
        },
        "success": true
      }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
JSON
var newMovie = JSON.parse(JSON.stringify(movie))
ready
jQuery
var newMovie = jQuery.extend(true, {}, movie)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by maikudou on