Skip to content

Instantly share code, notes, and snippets.

View gitmil's full-sized avatar

Hemil patel gitmil

View GitHub Profile
const someObj = {};
someObj.someProp = "I am here";
console.log(someObj.hasOwnProperty("someProp")); // true
let withoutPrototype = Object.create(null);
withoutPrototype.someProp = "I am here too"
console.log(Object.hasOwn(withoutPrototype, "someProp" )) //true
console.log(withoutPrototype.hasOwnProperty("someProp"))
//error withoutPrototype.hasOwnProperty is not a function
@gitmil
gitmil / JSErrorCause
Created February 20, 2022 19:09
JavaScript Error.cause example
function doWork() {
try {
doSomeWork();
} catch (err) {
throw new Error('Some work failed', { cause: err });
}
try {
doMoreWork();
} catch (err) {
throw new Error('More work failed', { cause: err });
@gitmil
gitmil / JSreleativeIndexing
Created February 20, 2022 18:29
relative indexing in JavaScript
const nums = [0, 1, 2, 3, 4, 5];
const lastElement = nums.at(-1);
const secondLastElement = nums.at(-2);
console.log(lastElement); // prints 5
console.log(secondLastElement); // prints 4
@gitmil
gitmil / JSPrivateClassMethods
Created February 20, 2022 18:04
JavaScript Private Class Methods Example
class Counter {
#x = 0;
#increment() {
this.#x++;
}
#print() {
return this.#x;
}
@gitmil
gitmil / JSClassPrivateField
Created February 20, 2022 17:26
JavaScript Private call field example
class Counter {
#x = 0; // private class field
increment() {
this.#x++;
}
print() {
return this.#x;
}
@gitmil
gitmil / JSClassPublicFiled
Created February 20, 2022 17:08
JavaScript Class Public Instance Field
class Counter {
x = 0; // public class field
increment() {
this.x++;
}
print() {
return this.x;
}
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Hello World',
Title: `First Ember Page`,
actions:{
testAction(){
console.log('Action Click');
}
}