`

JavaScript Core chapter 10

    博客分类:
  • ajax
 
阅读更多

一些基础概念:

#1 JavaScript 对象其实就是属性的集合。属性由键值对组成。通过[属性名]这种形式则总是可以保证正确性。

#2 函数: 函数本身也是对象。

function func(id){};

相当于:

var func = function(id){};

#3 this 表示当前上下文,即调用者的引用。

#4 词法作用域 即是在定义的时候就确定下来了。

#5 scope 在执行一个函数时,函数的参数和其局部变量会作为调用对象的属性进行存储

#6 call & apply

#7  由于构造函数定义了一个对象的类,所以属性constructor在有助于确定给定对象的类型.如,可以使用如下代码来确定一个未知对象的类型:if ((typeof o == "object") && (o.constructor == Date)),也可以用instanceof运算符:if ((typeof o == "object") && (o instanceof Date))

#8 对象的引用机制:对象不会被复制,只能通过引用来传递。

var recordDefParams = [];

recordDefParams[0] = {name:'id',type:'date'};
recordDefParams[1] = {name:'version'};
recordDefParams[recordDefParams.length] = {name:'deleted'};
function func(recordDefParams){
    for (var i = 0, nLen = recordDefParams.length; i < nLen; i++) {
        var obj = recordDefParams[i];
        if (obj.type == 'date' && !obj.dateFormat) {
            obj.dateFormat = 'xxx-xx-x';
        }
    }
    return recordDefParams;
}
console.dir(recordDefParams);
console.log('===========================');
console.dir(func(recordDefParams));
 

#9

 

 

function addr(street, xno){
    console.log(this);
    this.street = street || 'beijinglu';
    this.xno = xno || '1 hao';
    this.toString = function(){
        return 'Street:' + this.street + ' xno:' + this.xno;
    };
};
var core1 = new addr();
console.log(core1.toString());
var core2 = new addr('北京路','一号');
console.log(core2.toString());
 

 

//动态构建新的匿名对象
function point(x,y){
    this.x = x;
    this.y = y;
    return {'x':x,'y':y};
}
var a = point(3,4);
console.dir(a);
for(var key in a ){
   console.log(key);
   console.log(a[key]);
}
 

 

After read the blog of "JavaScript Core chapter 10 .writer the coding below for testing.

<html>
	<head>
		<title>
			 Js core
		</title>
		<script type="text/javascript">
			//原型链
			var base = {
				name : 'Mark',
				getName : function(){
					return this.name;
				}
			};
			var ext1 ={
				id :'0',
				__proto__ :base
			};
			var ext2 ={
				id : '9',
				__proto__ : base
			};
			//console.log(ext1.getName());
			
			//构造器
			function Task(id){
				this.id = id;
			};
			Task.prototype.status = 'defalt_begin';
			Task.prototype.execute = function(args){
				return 'execute task_[' + this.id + ']' + this.status + ':' + args;
			};
			var task1 = new Task(1);
			var task2 = new Task(2);
			task1.status = 'activing';
			task2.status = 'end...';
			//console.log(task1.execute('task_1'));
			//console.log(task2.execute('task_2'));
			
			//this understander
			var global = this;
			var tom = {
				name : 'tom',
				id : '1',
				getInfo: function(){
					console.log(this.name + ':' + this.id);
				}
			}
			var jetty = {
				name : 'jetty',
				getInfo : tom.getInfo 
				//等同于
				//getInfo:function (){ console.log(this.name + ':' + this.id);} 在跑构造的时候就创建好了。
			}
			
			tom.getInfo();
			jetty.getInfo();
			global.getInfo = tom.getInfo;
			global.getInfo();
		</script>
	</head>
	<body>
		 js core chapter 10 & 11.
	</body>
</html>

   all : 给全局对象动态的添加一个属性。

分享到:
评论

相关推荐

    JavaScript权威指南(第6版).JavaScript:The.Definitive.Guide

    Since 1996, JavaScript: The Definitive Guide has been the bible for JavaScript programmers—a programmer's guide and comprehensive reference to the core language and to the client-side JavaScript APIs...

    JavaScript权威指南(第6版)

    Since 1996, [removed] The Definitive Guide has been the bible for JavaScript programmers—a programmer's guide and comprehensive reference to the core language and to the client-side JavaScript APIs ...

    JavaScript权威指南(第6版)--JavaScript:The.Definitive.Guide

    Since 1996, [removed] The Definitive Guide has been the bible for JavaScript programmers—a programmer's guide and comprehensive reference to the core language and to the client-side JavaScript APIs ...

    Beginning.JavaScript.5th.Edition

    Title: Beginning JavaScript, 5th Edition Author: Jeremy McPeak Length: 768 pages ...Appendix B: Javascript Core Reference Appendix C: W3C Dom Reference Appendix D: Latin-1 Character Set

    JavaScript Functional Programming for JavaScript Developers (PDF, EPUB, MOBI)

    Chapter 10: Messaging Patterns Chapter 11: Microservices Chapter 12: Patterns for Testing Chapter 13: Advanced Patterns Chapter 14: ECMAScript-2015/2016 Solutions Today Module 3: Functional ...

    Data Wrangling with JavaScript

    Data Wrangling with JavaScript teaches readers core data munging techniques in JavaScript, along with many libraries and tools that will make their data tasks even easier. Table of Contents Chapter ...

    JavaScript 圣经第5版-Javascript编程宝典--黄金版 .rar

    Chapter 10: Strings, Math, and Dates. Chapter 11: Scripting Frames and Multiple Windows. Chapter 12: Images and Dynamic HTML. Part III: Document Objects Reference. Chapter 13: JavaScript ...

    Functional.Programming.in.JavaScript.1784398225

    The book first explores the core concepts of functional programming common to all functional languages, with examples of their use in JavaScript. It's followed by a comprehensive roundup of functional...

    Advanced.Game.Design.with.HTML5.and.JavaScript.1430258004

    Title: Advanced Game Design with HTML5 and JavaScript Author: Rex van der Spuy ...Chapter 10. Tweening Chapter 11. Make Your Own Game Engine Appendix A: Vectors for Movement and Collision Detection

    JavaScript权威指南

    Chapter 10. Pattern Matching with Regular Expressions Section 10.1. Defining Regular Expressions Section 10.2. String Methods for Pattern Matching Section 10.3. The RegExp Object Chapter 11...

    Beginning JavaScript 4th Edition Oct 2009

    Appendix B: JavaScript Core Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . 665 Appendix C: W3C DOM Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 697 Appendix...

    ppk on Javascript (pdf)

    Chapter 10. Data retrieval Section A. Sending the request Section B. Handling the response Section C. The response format Section D. Accessibility Afterword The future of JavaScript

    avaScript.Concurrency.178588923

    About This Book Apply the core principles of concurrency to both browser and server side development Explore the latest tools and techniques at the ...Chapter 10: Building a Concurrent Application

    Understanding.ECMAScript.6.159327757

    ECMAScript 6 represents the biggest update to the core of JavaScript in the history of the language. In Understanding ECMAScript 6, expert developer Nicholas C. Zakas provides a complete guide to the ...

    高清Building Web Applications with Visual Studio 2017及源码

    Chapter 2: Building the Data Access Layer with Entity Framework Core Chapter 3: Building the RESTful Service with ASP.NET Core MVC Services Chapter 4: Introducing ASP.NET Core MVC Web Applications ...

    learning javascript

    Using line-by-line code walkthroughs and end-of-chapter exercises, top web developer and speaker Tim Wright will help you get results fast, even if you've never written a line of JavaScript before....

    [ASP.NET.3.5高级程序设计(第2版)].Pro.ASP.NET.3.5.in.C#.2008.2th.edtion.pdf

    CHAPTER 10 Rich Data Controls 385 CHAPTER 11 Caching and Asynchronous Pages 451 CHAPTER 12 Files and Streams 497 CHAPTER 13 LINQ 531 CHAPTER 14 XML 587 PART 3 Building ASP.NET Websites CHAPTER ...

    Learning Javascript

    Using line-by-line code walkthroughs and end-of-chapter exercises, top web developer and speaker Tim Wright will help you get results fast, even if you've never written a line of JavaScript before....

Global site tag (gtag.js) - Google Analytics