This file contains 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
var person = { | |
firstName: 'Hoang', | |
lastName: 'Pham', | |
showName: function() { | |
console.log(this.firstName + ' ' + this.lastName); | |
} | |
}; | |
//Ở đây this sẽ là object person | |
person.showName(); //Hoang Pham. |
This file contains 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
var person = { | |
firstName: 'Hoang', | |
lastName: 'Pham', | |
showName: function() { | |
console.log(this.firstName + ' ' + this.lastName); | |
} | |
}; | |
$('button').click(person.showName); //showName truyền vào như callback, ở đây this chính là button |
This file contains 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
var person = { | |
firstName: 'Hoang', | |
lastName: 'Pham', | |
friends : ['Minh', 'Sang', 'Khoa', 'Hoang'], | |
showFriend: function() { | |
for(var i = 0; i < this.friends.length; i++) | |
console.log(this.firstName + ' have a friend named ' + this.friends[i]); | |
}, | |
showFriendThis: function() { | |
this.friends.forEach(function(fr){ |
This file contains 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
var person = { | |
firstName: 'Hoang', | |
lastName: 'Pham', | |
friends : ['Minh', 'Sang', 'Khoa', 'Hoang'], | |
showFriendFixed: function() { | |
var personObj = this; //Gán giá trị this vào biến personObj | |
this.friends.forEach(function(fr){ | |
console.log(personObj.firstName + ' have a friend named ' + fr); | |
}); | |
} |
This file contains 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
var person = { | |
firstName: 'Hoang', | |
lastName: 'Pham', | |
showName: function() { | |
console.log(this.firstName + ' ' + this.lastName); | |
} | |
}; | |
//Ở đây this sẽ là object person, chạy đúng | |
person.showName(); //Hoang Pham. |
This file contains 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
var person = { | |
firstName: 'Hoang', | |
lastName: 'Pham', | |
showName: function() { | |
console.log(this.firstName + ' ' + this.lastName); | |
} | |
}; | |
var showNameFunc = person.showName.bind(person); //Gán function vào biến showNameFunc | |
showNameFunc(); //Chạy đúng vì this bây giờ là object person, do ta đã bind |
This file contains 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 Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains 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
public string getUpperName(string name) | |
{ | |
return name.ToUpper(); | |
} | |
// Hàm A này sẽ bị lỗi | |
var upperNames = _db.Users.Select(x => getUpperName(x.Name)).ToList(); | |
// Hàm B này không lỗi | |
var upperNames = _db.Users.Select(x => x.Name.ToUpper()).ToList(); |
This file contains 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
public class Student { | |
public string Name { get; set;} | |
public int Age { get; set;} | |
// Format class này dưới dạng text, html, json để in ra | |
public string GetStudentInfoText() { | |
return "Name: " + Name + ". Age: " + Age; | |
} | |
public string GetStudentInfoHTML() { | |
return "<span>" + Name + " " + Age + "</span>"; |
This file contains 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
request({ | |
url: this._analyzeApiUrl, // Thay bằng URL của API | |
headers: { | |
"Ocp-Apim-Subscription-Key": this._analyzeKey // Thay bằng key của bạn | |
}, | |
method: "POST", | |
json: true, | |
body: { | |
"url": imageUrl // Thay bằng url của hình ảnh | |
} |
OlderNewer