Skip to content

Instantly share code, notes, and snippets.

View linx4200's full-sized avatar

liuxinran linx4200

  • Shenzhen, China
View GitHub Profile
@linx4200
linx4200 / patterns-inheritance-prototypal.js
Created March 17, 2018 12:32
【继承】原型式继承
function inheritObject(o) {
// 声明一个过渡函数对象
function F () {};
// 过渡对象的原型继承父对象
F.prototype = o;
// 返回过渡对象的一个实例
return new F();
}
@linx4200
linx4200 / patterns-inheritance-constructor.js
Created March 17, 2018 08:00
【继承】构造函数继承
function SuperClass(id) {
this.id = id;
this.books = ['a' ,'b', 'c'];
}
SuperClass.prototype.showBooks = function () {
console.log(this.books);
}
function SubClass (id) {
@linx4200
linx4200 / patterns-inheritance-classical.js
Created March 17, 2018 07:53
【继承】类式继承
function SuperClass(params) {
this.superValue = true;
}
SuperClass.prototype.getSuperValue = function() {
return this.superValue;
}
function SubClass () {
this.subValue = false;
@linx4200
linx4200 / change-the-author-in-git.bash
Created April 27, 2017 14:18
change-the-author-in-git
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="[email protected]"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="[email protected]"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@linx4200
linx4200 / hijack-zhihu-copy.js
Last active August 17, 2016 02:10
你懂的。
$($('.zm-item-rich-text')).off().on('copy', function(){console.log('我hijack了你的copy!')});
@linx4200
linx4200 / sort-by-multiple-keys.rb
Last active August 7, 2016 15:50
根据多个键值来对数组排序
def sort_by_multiple_keys(arr)
# <=> operator to compare each element of the collection.
# This operator takes two arguments
# returns
# -1 if the first argument is less than the second argument
# 1 if the second argument is less than the first argument
# 0 if they're equivalent.
# 1 <=> 2 # => -1