'How to use Mozilla DevNet date polyfill in JavaScript

I wish to use the date polyfill mentioned here at MDN:

if (!Date.now) {
  Date.now = function now() {
    return new Date().getTime();
  };
}

How do I get this into a variable? I tried:

function get_date_string(){
    if (!Date.now) {
        Date.now = function() { return new Date().getTime(); }
    }
}

var ds = get_date_string();


Solution 1:[1]

Use it this way:

if (!Date.now) {
  Date.now = function now() {
    return new Date().getTime();
  };
}

var ds = Date.now();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lante