Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
    <title>https://stackoverflow.com/a/44198641/5846045</title>
</head>
<body></body>
</html>
 
const iframe = document.createElement('iframe');
document.body.appendChild(iframe);
const iWindow = iframe.contentWindow;
iWindow.document.write(`<script>var date = new Date()</script>`);
const checkedInstanceOfDate = iWindow.date instanceof Date;
const checkedPrototypeOfDate = Date.prototype.isPrototypeOf(iWindow.date);
const checkedSolutionFromSO = isValidDate(iWindow.date);
console.log(`x instanceof Date ⇒ ${checkedInstanceOfDate}`);
console.log(`Date.prototype.isPrototypeOf(x) ⇒ ${checkedPrototypeOfDate}`);
console.log(`Object.prototype.toString.call(x) === '[object Date]' ⇒ ${checkedSolutionFromSO}`);
function isValidDate(date) {
  return date && Object.prototype.toString.call(date) === "[object Date]" && !isNaN(date);
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
boghyonpro
0viewers