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
/** | |
* Example1: | |
* var Person, man; | |
* Person = Klass.create(); | |
* Person.implement(EventEmitter); | |
* man = Person.instance(); | |
* man.on('say', function(what) { alert(what); }); | |
* man.trigger('say', 'balabala...'); | |
* | |
* Example2: |
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 __hasProp, __extends; | |
__hasProp = {}.hasOwnProperty, | |
__extends = function (child, parent) { | |
for (var key in parent) { | |
if (__hasProp.call(parent, key)) child[key] = parent[key]; | |
} | |
function ctor() { | |
this.constructor = child; | |
} |
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
#!/usr/bin/env ruby | |
class MegaGreeter | |
attr_accessor :names | |
# Create the object | |
def initialize(names = "World") | |
@names = names | |
end |
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
// jqia | |
对象的本质是一个无序的 “名/值” 对应关系的集合,名称是字符串,值可以是任何Javascript对象。 | |
// this | |
在基于面向对象的语言里,`this`参数通常引用类的实例(方法在类中声明)。在Javascript中函数也是对象, | |
`this`所引用的对象被称为函数上下文,它不是由如何声明函数,而是由如何调用函数决定的。意味着更具函数 | |
如何被调用,同一函数可以有不同的上下文。在默认情况下,函数调用的上下文(this)是对象,其属性包含可 | |
以调用该函数的引用。 | |
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
// Prototypal Inheritatance Definition: | |
// When accessing the propertyies of an object, Javascript will traverse the prototype chain | |
// upwards until finds a property with the requested name. | |
// Most Javascript implementations use __proto__ property to represent the next object in the | |
// prototype chain. | |
// Note: __proto__ is non-standard and should not be used in your code. |
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
// Create an object with "No Properties" | |
var person = Object.create(null); | |
Object.defineProperty(person, 'fisrtName', { | |
value: "Jin Cheng", | |
writable: true, | |
enumerable: true, | |
configurable: true | |
}); |
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
// Safari on iOS viewport | |
// Executed at window onload. | |
this.viewport = function() { | |
var width, height, screenWidth, screenHeight, innerWidth, innerHeight, isSafariOnIOS, orientation, userAgent; | |
screenWidth = window.screen.width; | |
screenHeight = window.screen.height; | |
innerWidth = window.innerWidth; |
NewerOlder