Skip to content

Instantly share code, notes, and snippets.

View Jagathishrex's full-sized avatar
🎯
Focusing

Jagathishrex

🎯
Focusing
View GitHub Profile
"use strict";
let user = { name : "Jagathish" };
Object.isExtensible(user); // true
Object.preventExtensions(user);
Object.isExtensible(user); // false
"use strict";
let user = { name : "Jagathish" };
Object.preventExtensions(user);
try {
user.age = 23;
} catch (e) {
console.log(e);
// expected output: TypeError:Cannot add property age, object is not extensible
"use strict";
let user = {
name : "Jagathish",
age : 23,
mobile : 123123123,
address : "221B Baker Stree, London"
};
let handler = {
set(target, prop, val){

| Number | Rider | Time | | 1 | Bullet Bob | 56:07 | | 2 | Clumsy Colin | DNF | | 3 | Swift Susan | 55:13 |

let target = {};
let handler = {}; // empty handler
let proxy = new Proxy(target, handler);
proxy.test = 5; // the property will be added in target
target.test; // 5
proxy.test; // 5
let target = {
name : "Mia",
age : 28
};
let handler = {
get(targetObject, propertyName) {
if( propertyName in targetObject) {
return `The ${propertyName} is ${targetObject[propertyName]}`;
}
}
let fileInput = document.getElementById('file_chooser');
fileInput.addEventListener('change', function(e) {
var file = this.files[0];
var fd = new FormData();
fd.append("file", file);
var request = new XMLHttpRequest();
request.open('POST', 'http:myserver.com/upload');
let fileInput = document.getElementById('file_chooser');
fileInput.addEventListener('change', function(e) {
var file = this.files[0];
var fd = new FormData();
fd.append("file", file);
var request = new XMLHttpRequest();
request.open('POST', 'http:myserver.com/upload');
let url = "https://medium.com/search?q=javascriptjeep";
let request = new XMLHttpRequest();
console.log(request.readyState); // 0
//after calling open the state will be changed to 1
request.open("GET", url);
console.log(request.readyState); // 1
// we need to implement readystatechange event to detect 2,3,4, events
request.onreadystatechange = function() {
request.onprogress = function(e) { // triggers periodically
/*
e.loaded - how many bytes downloaded
e.lengthComputable = true if the server sent Content-Length header, if true we can find the size of the response
e.total - total number of bytes (if lengthComputable is true)
*/
let total = e.lengthComputable ? e.total : 0;
let loaded = e.loaded;
if(total) {