- Notifications
You must be signed in to change notification settings - Fork360
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletionsaccidental-global.js
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
| Original file line number | Diff line number | Diff 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
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
| Original file line number | Diff line number | Diff 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
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
| Original file line number | Diff line number | Diff 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| console.log(0.1 + 0.2 === 0.3); |
18 changes: 18 additions & 0 deletionsfunction-arrow-context.js
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
| Original file line number | Diff line number | Diff 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
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
| Original file line number | Diff line number | Diff 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
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
| Original file line number | Diff line number | Diff 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
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
| Original file line number | Diff line number | Diff 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
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
| Original file line number | Diff line number | Diff 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
Empty file.
7 changes: 7 additions & 0 deletionssemicolon-issue.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| function foo() { | ||
| return ; | ||
| { | ||
| message: "Hello World" | ||
| }; | ||
| } | ||
| console.log(foo()); //Undefined |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.