This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lang = ["Java", "JavaScript"]; | |
// element found in 1st index | |
lang.findIndex( (val) => val === "JavaScript" ); // 1 | |
// element not found so returns -1 | |
lang.findIndex( (val) => val === "Python" ); // -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let canvas; | |
let ctx; | |
function animate() { | |
// do animations here ... | |
const bitmap = canvas.transferToImageBitmap(); | |
self.postMessage({msg: 'render', bitmap}); // this will be handled in main thread , where we will update the content | |
self.requestAnimationFrame(animate); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvas = document.querySelector('#canvas'); | |
const ctx = canvas.getContext('bitmaprenderer'); // | |
const offscreenCanvas = new OffscreenCanvas(canvas.width, canvas.height); | |
const worker = new Worker('offscreen_worker2.js'); | |
worker.postMessage({msg: 'init', canvas: offscreenCanvas}, [offscreenCanvas]); | |
worker.addEventListener('message', function(ev) { | |
if(ev.data.msg === 'render') { | |
ctx.transferFromImageBitmap(ev.data.bitmap); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvas = document.querySelector('#canvas'); | |
canvas.getContext('webgl'); | |
try { | |
let offscreen = canvas.transferControlToOffscreen(); | |
}catch(e){ | |
console.log(e); | |
} | |
//DOMException: Failed to execute 'transferControlToOffscreen' on 'HTMLCanvasElement': | |
// Cannot transfer control from a canvas for more than one time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let canvas; | |
let ctx; | |
function animate() { | |
// some animations | |
self.requestAnimationFrame(animate); | |
} | |
self.onmessage = function(ev) { | |
if(ev.data.msg === 'offscreen') { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvas = document.querySelector('#canvas'); | |
const offscreenCanvas = canvas.transferControlToOffscreen(); | |
const worker = new Worker('offscreen_worker.js'); | |
worker.postMessage({msg: 'offscreen', canvas: offscreenCanvas}, [offscreenCanvas]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
let empty = Object.preventExtensions({}); | |
empty.__proto__ = { name: 'jagathish' }; // TypeError : #<Object> is not extensible |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
let user = { name : "Jagathish" }; | |
Object.preventExtensions(user); | |
try { | |
Object.defineProperty(user, 'age', { | |
value: 23 | |
}); | |
} catch (e) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
let user = { name : "Jagathish", age : 23 }; | |
Object.preventExtensions(user); | |
delete user.age; | |
console.log(user); //{name: "Jagathish"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
let user = { name : "Jagathish" }; | |
Object.preventExtensions(user); | |
// user.age = 23; --> this will throw error | |
user.__proto__.age = 23; // adding property to object prototype |