Object-Oriented Code

1.

var Person = function (name) {
this.name = name;
};

Person.prototype.say = function (words) {
alert(this.name + ' says "' + words + '"');
};
var tom = new Person("tom");
tom.say("Hello");

2.Inheritance and object-oriented programming

constructor pattern


Creating Elements

1.<div class="note">Hello</div>.

var div = document.createElement('div');
if (div.textContent) { div.textContent = "Hello!"; } 
else if (div.innerText) { div.innerText = "Hello!"; }
div.setAttribute('class', 'note');
document.body.appendChild(div);

2.

div.parentNode.removeChild(div);

3.

var div = $('<div/>').text("Hello").appendTo(document.body);
$('<span/>').text('Hello!').appendTo(div);

Canvas?

1.<script>
    var canvas = document.querySelector('canvas'),
        ctx = canvas.getContext('2d');
    ctx.fillRect(top-left-corner-x, top-left-corner-y, width, height);

</script>

2.Animation??


Local Storage

1.

// Object example

localStorage.setItem('user', JSON.stringify({
username: 'htmldog',
api_key: 'abc123xyz789'
})); var user = JSON.parse(localStorage.getItem('user'));

2.Local storage can only save strings,the object must be run through JSON.parse on the way out of local storage.


Errors & Exceptions

1.

try {
JSON.parse("a"); // Produces a SyntaxError
} catch (error) {
// Handle the error
alert(error.message);
}

2.Creating error

throw new Error("I hungry. Fridge empty.");

Regular Expressions……

1.Used to Serarch & Match Strings to identify or replace

2.var regex=/ ^[a-z\s]+$/;

//--expression

[]--repeated one or more times

a-z--letter a to z ,lowercase

\s--white-space

$--up to end the string

3.

var lowerCaseString = 'some characters';

if (lowerCaseString.match(regex)) {
alert('Yes, all lowercase');
}

4.

var text = "Everything and nothing.";

text = text.replace(/(every|no)thing/gi, "something");

g--global flag ,match all occurrences rather then just the first

i--case-insensitive flag,did not care about uppercase &lowercase letters


Closures……

1.

var add = function (a) {
return function (b) {
return a + b;
};
}; var addFive = add(5); alert(addFive(10));//15
var hello = add('Hello ');

alert(hello('tom'));// Hello tom

2.A function that returns a function


Node.js

1.Node is a platform for building servers in JavaScript,built on Google’s V8 JavaScript engine

Using DOM APIs  are available on the other side of the client/sever divide in the form of just Node

2.Install

nodejs.org

npm(Node package Manager)

Node comes with a core set of modules, one of which is “http”, used to set up a web server


JS Apps

1.Moduarity

2.MVC


Backbone

1.Add structure to client-side applications,to avoid a spaghetti-code mess.

Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.

2.

connect model up to a view via a template which is used to indicate where the model’s data should go.

jQuery and Underscore.


Angular

1.open-source client-side JS framework that uses HTML as its templating language

Declarative programming is better than imperative programming

2.create

connects the value of the input to a model called “name”

bind to the value of the “name” model. When you update the input, the h1 will update too.

3.build something useful

4.scope

5.dependency injection

6.smaller

【JS】Advanced1:Object-Oriented Code的更多相关文章

  1. 【HTML】Intermediate2:Text: AbbreviationsQuotations Code

    1.</abbr> attribute:title 2.Quotations blockquote :standalone often multi-line quotations-cite ...

  2. 【HTML】Advanced1:Text: Time, Mark, and "Presentational"

    1.Exploring the depths of HTML5 2.</time> <p>Written by Doctor Who on <time datetime= ...

  3. 【CSS3】Advanced1:Rounded Corners

    1.Border radius The border-radius property can be used to working clockwise from top-left set border ...

  4. 【JS】AJAX跨域-被调用方与调用方解决方案(二)

    解决跨域问题 跨域问题说明,参考[JS]AJAX跨域-JSONP解决方案(一) 实例,使用上一章([JS]AJAX跨域-JSONP解决方案(一))的实例 解决方案三(被调用方支持跨域-服务端代码解决) ...

  5. 【js】appendChild

    appendChild主要是用来追加节点插入到最后:循环的时候由于不停的搬家导致length在改变.     使用for循环 <!Doctype html> <html xmlns= ...

  6. 【js】Leetcode每日一题-制作m束花所需的最少天数

    [js]Leetcode每日一题-制作m束花所需的最少天数 [题目描述] 给你一个整数数组 bloomDay,以及两个整数 m 和 k . 现需要制作 m 束花.制作花束时,需要使用花园中 相邻的 k ...

  7. 【js】Leetcode每日一题-完成所有工作的最短时间

    [js]Leetcode每日一题-完成所有工作的最短时间 [题目描述] 给你一个整数数组 jobs ,其中 jobs[i] 是完成第 i 项工作要花费的时间. 请你将这些工作分配给 k 位工人.所有工 ...

  8. 【js】Leetcode每日一题-数组异或操作

    [js]Leetcode每日一题-数组异或操作 [题目描述] 给你两个整数,n 和 start . 数组 nums 定义为:nums[i] = start + 2*i(下标从 0 开始)且 n == ...

  9. 【js】Leetcode每日一题-解码异或后数组

    [js]Leetcode每日一题-解码异或后数组 [题目描述] 未知 整数数组 arr 由 n 个非负整数组成. 经编码后变为长度为 n - 1 的另一个整数数组 encoded ,其中 encode ...

随机推荐

  1. Apache2.2+php5.4在windows上配置实例

    这几天一直在win8.1上配置apache+php环境,网上看了很多文章,自己又犯了很多错误才配置成功,对新手来说真是有点小难. 自己打算把配置的详细过程写下来,好帮助其他新手快速配置. 在这里参考了 ...

  2. Scrum中的User Story

    我们通常用User Story来描述Backlog里的各个Backlog项,User Story是从用户的角度对系统的某个功能模块所作的简短描述.一个User Story描述了项目中的一个小功能,以及 ...

  3. 用 OneAPM Cloud Insight 监控 Docker 性能

    Docker 是构建和部署软件的一个新兴的轻量级的平台,也是一个减轻替代虚拟机的容器.Docker 通过给开发者提供兼容不同环境的镜像,成为解决现代基础设施的持续交付的一个流行的解决方案. 和虚拟机一 ...

  4. 如何定位Release 版本中程序崩溃的位置 ---利用map文件 拦截windows崩溃函数

    1       案例描述 作为Windows程序员,平时最担心见到的事情可能就是程序发生了崩溃(异常),这时Windows会提示该程序执行了非法操作,即将关闭.请与您的供应商联系.呵呵,这句微软的“名 ...

  5. CodeForces 299A Ksusha and Array

    http://codeforces.com/problemset/problem/299/A 题意 :输入n个数,要求找出一个数能让其他所有的数整除,如果没有的话输出-1.有多个的话输出其中一个. 思 ...

  6. 学习记录:浏览器JAVASCRIPT里的WINDOWS,DOCUMNET

    看完以下这段话之后,就理解DOCUMNET.READY之类的说法了. 或是JAVASCRIPT的浏览器里更细致的操作DOCUMENT的东西了. DOCUMNET和WINDOWS谁大谁小, 立即执行的匿 ...

  7. 【BZOJ 1185】 凸包+旋转卡壳

    Description [分析] 打计算几何真的可以哭出来... 跟那个求线段最远点差不多,这题弄三个东西转一转,一个表示左端最远点,一个表示右端最远点,一个表示上面最远点. 左右两边的最远点用点积判 ...

  8. highcharts 切换

    <!doctype html> <html lang="en"> <head> <script type="text/javas ...

  9. ArcGIS学习记录—ArcGIS ArcMap编辑状态中线打断的问题

    摘要:在处理数据时,我们经常会遇到线打断的问题,比如需要指定在线上某处打断线,或者新建网络数据集时需要在线的交点处打段线等等.现将桌面版中我所遇到的线打断的工具总结如下: 在ArcGIS矢量处理数据时 ...

  10. php 23种设计模式的趣味解释

    http://wenku.baidu.com/link?url=GwvuvSOdJneZQc-DSKoGmPcxTtzn3cdtIp3fRaCNbkg1zJDZZZTx2NwEK5IsqU996fG3 ...