【JS】Advanced1:Object-Oriented Code

时间:2022-02-06 12:23:36

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)

【JS】Advanced1:Object-Oriented Code

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.【JS】Advanced1:Object-Oriented Code

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

【JS】Advanced1:Object-Oriented Code

【JS】Advanced1:Object-Oriented Code

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

【JS】Advanced1:Object-Oriented Codeconnects 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

【JS】Advanced1:Object-Oriented Code

4.scope【JS】Advanced1:Object-Oriented Code

5.dependency injection

6.smaller

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

  1. 【HTML】Intermediate2:Text&colon; AbbreviationsQuotations Code

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

  2. 【HTML】Advanced1:Text&colon; Time&comma; Mark&comma; and &quot&semi;Presentational&quot&semi;

    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. Cesium的api之关于viewer

    1.viewer是用来构建三维的主要的部件:通过创建viewer可以完成三维的图片.地形的展示等 2.属性 * @param {Element|String} container :指定的是在html ...

  2. UVA 11762 Race to 1(记忆化&plus;期望)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20869 [思路] DP+期望. 设f[x]表示从x转移到1的期望操 ...

  3. top命令的解释

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.下面详细介绍它的使用方法. top - 01:06:48 up  1:22,   ...

  4. 简单的java缓存实现

    扫扫关注"茶爸爸"微信公众号 坚持最初的执着,从不曾有半点懈怠,为优秀而努力,为证明自己而活. 提到缓存,不得不提就是缓存算法(淘汰算法),常见算法有LRU.LFU和FIFO等算法 ...

  5. IONIC之简易购物车

    HTML <div ng-app="app"> <div class="l-header"> <div class="l ...

  6. Android动画&lpar;一&rpar;-视图动画与帧动画

    项目中好久没用过动画了,所以关于动画的知识都忘光了.知识总是不用则忘.正好最近的版本要添加比较炫酷的动画效果,所以也借着这个机会,写博客来整理和总结关于动画的一些知识.也方便自己今后的查阅. Andr ...

  7. tomcat启动超过时间

    Server Tomcat v9.0 Server at localhost was unable to start within 45 seconds. 运行超时 最近我切换了JDK版本之后,将10 ...

  8. 基于VS2017的Docker Support体检ASP&period;NET Core站点的Docker部署

    最近在学习如何用 Docker 部署生产环境中的 ASP.NET Core 站点,作为一个 Docer 新手,从何处下手更容易入门呢?一开始就手写 Docker 配置文件(Docfile, docke ...

  9. 我的MVP呢?

    Ladies and gentelmen, welcome the MVP of NBA 16-2017 Season:... 呃,等下,好像哪里不对.那是因为,我要说的MVP根本就不是Most Va ...

  10. Windows Server 2008中安装IIS7&period;0

    最近由于需求重新部署了一台服务器Windows Server 2008,由于以前都是在Windows Server 2003上操作,因此记录下,供其他同学参考.   下面主要介绍在Windows Se ...