Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

new javascript concept#71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
spandey1296 merged 1 commit intomainfromspandey1296-patch-1
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletionsaccidental-global.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
function foo() {
let y = x = 0; // window object
x++;
y++;
return x;
}

console.log(foo(), typeof x, typeof y);
22 changes: 22 additions & 0 deletionsclass-multiple-constructors.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}

constructor(width) {
this.width = width;
}
// Getter
get area() {
return this.calcArea();
}
// Method
calcArea() {
return this.height * this.width;
}
}

const square = new Rectangle(20, 30);

console.log(square.area); // 600
8 changes: 8 additions & 0 deletionseventloop-order.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
function main(){
console.log('A');
setTimeout(
function print(){ console.log('B'); }
,0);
console.log('C');
}
main(); // A,C and B
1 change: 1 addition & 0 deletionsfloatingpoint-problem.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
console.log(0.1 + 0.2 === 0.3);
18 changes: 18 additions & 0 deletionsfunction-arrow-context.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
function User(name, age) {
this.name = name;
this.age = age;

this.getProfile = function() {
// Outer function context
console.log(this.constructor.name); // User
return () => {
// Inner function context
console.log(this.constructor.name); // User(Get it from the outer context)
console.log("I'm " + this.name + ", " + this.age + " yrs old");
};
}
}

let user = new User('John', 25);
let profile = user.getProfile();
profile(); //I'm John, 25 yrs old
18 changes: 18 additions & 0 deletionsfunction-context.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
function User(name, age) {
this.name = name;
this.age = age;

this.getProfile = function() {
// Outer function context
console.log(this.constructor.name); // User
return function() {
// Inner function context
console.log(this.constructor.name); // Window
console.log("I'm " + this.name + ", " + this.age + " yrs old");
};
}
}

var user = new User('John', 25);
var profile = user.getProfile();
profile(); //I'm undefined, undefined yrs old
8 changes: 8 additions & 0 deletionsfunction-expression.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
var y = 1;

console.log(y);
if (function f(){}) {
y += typeof f;
console.log(y);
}
console.log(y);
11 changes: 11 additions & 0 deletionsfunction-hoisted.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
let obj=['love', 'blue', 1016, 'india']
var car = Vehicle.apply({}, obj);
console.log(car);

function Vehicle(model, color, year, country) {
this.model = model;
this.color = color;
this.year = year;
this.country = country;
return this
}
9 changes: 9 additions & 0 deletionsfunction-without-new.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
function Vehicle(model, color, year, country) {
this.model = model;
this.color = color;
this.year = year;
this.country = country;
}

var car = new Vehicle("Honda", "white", "2010", "UK");
console.log(car);
Empty file addedfunctiontest.js
View file
Open in desktop
Empty file.
7 changes: 7 additions & 0 deletionssemicolon-issue.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
function foo() {
return ;
{
message: "Hello World"
};
}
console.log(foo()); //Undefined

[8]ページ先頭

©2009-2025 Movatter.jp