I am curious why this returns the same timestamp for each. The object should have different identifiers I would think.?
/js/helpers/v01.js
var Tester = (function () {
var object_id = 'Tester';
var object_id_unique = (new Date().getTime()) + '-' + (new Date().getMilliseconds());
var _this;
/**
*
* @constructor
*/
function Tester(obj_name) {
this.name = obj_name;
this.run();
}
Tester.prototype = {
run: function () {
"use strict";
var $body = document.getElementsByTagName('body')[0];
var $node = document.createElement('div');
$node.innerHTML = '<lable>' + this.name + ': </lable>' + ' ' + object_id + '-' + object_id_unique;
$body.appendChild($node);
}
};
return Tester;
})();
Here is the page
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="/js/helpers/v01.js"></script>
</head>
<body>
<script type="text/javascript">
new Tester('A');
setTimeout(function () {
new Tester('B');
}, 500);
</script>
</body>
</html>
My output return this
A: Tester-1385613846838-838
B: Tester-1385613846838-838
console.log('foo')beforevar object_id_unique = ...;and see how often it executes. I recommend to learn how to debug JavaScript so that you can set breakpoints, inspect variables etc.