
javascript
jardownload
这个作者很懒,什么都没留下…
展开
-
Javascript 面向对象编程
http://trix.iteye.com/blog/617250 Javascript 面向对象编程(一):封装http://www.ruanyifeng.com/blog/2010/05/object-oriented_javascript_encapsulation.htmlJavascript面向对象编程(二):继承http://www.ruanyifeng...原创 2010-08-10 15:26:27 · 105 阅读 · 0 评论 -
Instantiation
[b]What does the new operator do?[/b][code="java"] function Ninja(){ this.name = "Ninja"; } var ninjaA = Ninja(); assert( !ninjaA, "Is undefined, not an instance of Ninja." ); var ni...原创 2010-08-11 16:20:24 · 177 阅读 · 0 评论 -
Defining Functions
[b]What ways can we define functions?[/b][code="java"] function isNimble(){ return true; } var canFly = function(){ return true; }; window.isDeadly = function(){ return true; }; log(isNimble, ...原创 2010-08-11 16:20:24 · 97 阅读 · 0 评论 -
Inheritance
[b]The basics of how prototypal inheritance works.[/b][code="java"] function Person(){} Person.prototype.dance = function(){}; function Ninja(){} // Achieve similar, but non-inheritable,...原创 2010-08-11 16:20:23 · 106 阅读 · 0 评论 -
Context
[b]What happens if a function is an object property?[/b][code="java"] var katana = { isSharp: true, use: function(){ this.isSharp = !this.isSharp; } }; katana.use(); assert( !...原创 2010-08-11 16:20:23 · 125 阅读 · 0 评论 -
Temporary Scope
[b]Self-executing, temporary, function[/b][code="java"] (function(){ var count = 0; var timer = setInterval(function(){ if ( count < 5 ) { log( "Timer call: ", count ); ...原创 2010-08-11 16:20:23 · 106 阅读 · 0 评论 -
Closures
[b]A basic closure.[/b][code="java"] var num = 10; function addNum(myNum){ return num + myNum; } assert( addNum(5) == 15, "Add two numbers together, one from a closure." );[/code][b]But why...原创 2010-08-11 16:20:23 · 101 阅读 · 0 评论 -
Named Functions
[b]We can refer to a function, within itself, by its name.[/b][code="java"] function yell(n){ return n > 0 ? yell(n-1) + "a" : "hiy"; } assert( yell(4) == "hiyaaaa", "Calling the function...原创 2010-08-11 16:20:23 · 139 阅读 · 0 评论 -
Built-in Prototypes
[b]We can also modify built-in object prototypes.[/b][code="java"] if (!Array.prototype.forEach) { Array.prototype.forEach = function(fn){ for ( var i = 0; i < this.length; i++ ) { ...原创 2010-08-11 16:20:23 · 82 阅读 · 0 评论 -
Flexible Arguments
[b]Using a variable number of arguments to our advantage.[/b][code="java"] function merge(root){ for ( var i = 0; i < arguments.length; i++ ) for ( var key in arguments[i] ) roo...原创 2010-08-11 16:20:23 · 113 阅读 · 0 评论 -
Instance Type
[b]Examining the basics of an object.[/b][code="java"] function Ninja(){} var ninja = new Ninja(); assert( typeof ninja == "object", "However the type of the instance is still an object." );...原创 2010-08-11 16:20:22 · 92 阅读 · 0 评论 -
Our Goal
[b]Goal: To be able to understand this function:[/b][code="java"]// The .bind method from Prototype.js Function.prototype.bind = function(){ var fn = this, args = Array.prototype.slice.call(arg...原创 2010-08-11 16:20:22 · 109 阅读 · 0 评论 -
Function Prototypes
[b]Adding a prototyped method to a function.[/b][code="java"] function Ninja(){} Ninja.prototype.swingSword = function(){ return true; }; var ninjaA = Ninja(); assert( !ninjaA, "Is...原创 2010-08-11 16:20:22 · 544 阅读 · 0 评论 -
Enforcing Function Context
[b]What happens when we try to bind an object's method to a click handler?[/b][code="java"] var Button = { click: function(){ this.clicked = true; } }; var elem = document.creat...原创 2010-08-11 16:20:22 · 82 阅读 · 0 评论 -
Functions as Objects
[b]How similar are functions and objects?[/b][code="java"] var obj = {}; var fn = function(){}; assert( obj && fn, "Both the object and function exist." ); [/code][b]How similar are fun...原创 2010-08-11 16:20:22 · 110 阅读 · 0 评论 -
Bonus: Function Length
[b]How does a function's length property work?[/b][code="java"] function makeNinja(name){} function makeSamurai(name, rank){} assert( makeNinja.length == 1, "Only expecting a single argument" );...原创 2010-08-11 16:20:24 · 104 阅读 · 0 评论