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
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 |
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
$($('.zm-item-rich-text')).off().on('copy', function(){console.log('我hijack了你的copy!')}); |
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
function SuperClass(params) { | |
this.superValue = true; | |
} | |
SuperClass.prototype.getSuperValue = function() { | |
return this.superValue; | |
} | |
function SubClass () { | |
this.subValue = false; |
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
function SuperClass(id) { | |
this.id = id; | |
this.books = ['a' ,'b', 'c']; | |
} | |
SuperClass.prototype.showBooks = function () { | |
console.log(this.books); | |
} | |
function SubClass (id) { |
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
function inheritObject(o) { | |
// 声明一个过渡函数对象 | |
function F () {}; | |
// 过渡对象的原型继承父对象 | |
F.prototype = o; | |
// 返回过渡对象的一个实例 | |
return new F(); | |
} |
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
var BasketBall = function () { /* ... */}; | |
var FootBall = function () { /* ... */}; | |
var Tennis = function () { /* ... */}; | |
// 运动工厂 | |
var sportsFactory = function (name) { | |
switch(name) { | |
case 'NBA': | |
return new BasketBall(); | |
case 'WorldCup': |
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
// 安全模式创建的工厂类 | |
var Factory = function(type, content) { | |
if (this instanceof Factory) { | |
return new this[type](content); | |
} else { | |
return new Factory(type, content); | |
} | |
} | |
// 工厂原型中设置创建所有类型数据对象的基类 |
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
var A = { | |
Util: { | |
util_method1: function() {}, | |
util_method2: function() {}, | |
// ... | |
}, | |
Tool: { | |
tool_method1: function() {}, | |
tool_method2: function() {}, | |
// ... |
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
var LazySingleton = (function() { | |
// 单例实例引用 | |
var instance = null; | |
// 单例 | |
function Singleton() { | |
return { | |
publicMethod: function() {}, | |
publicProperty: '1' | |
} | |
} |
OlderNewer