prototype使得js面向对象
使用了prototype之后,使用它里面的属性或者函数 需要new出一个对象才可以使用。
否则不使用prototype,直接向对象注入
 function Person(){

 }
Person.prototype.a = 5;
Person.prototype.b = function(){
alert("bbb");
}
var p = new Person();
alert(p.a);
p.b();
alert(p.constructor); function SupPerson(){ }
//SupPerson.prototype = Person.prototype;
SupPerson.prototype = p;
var sp = new SupPerson();
sp.b();

prototype 用法的更多相关文章

  1. js中prototype用法(转)

    JavaScript能够实现的面向对象的特征有:·公有属性(public field)·公有方法(public Method)·私有属性(private field)·私有方法(private fie ...

  2. 第197天:js---caller、callee、constructor和prototype用法

    一.caller---返回函数调用者 //返回函数调用者 //caller的应用场景 主要用于察看函数本身被哪个函数调用 function fn() { //判断某函数是否被调用 if (fn.cal ...

  3. javascript当中prototype用法

    prototype见上一节,马克-to-win:prototype作用就是给某个类增加一个实例方法. 例 3.6.2 <head>    <meta http-equiv=" ...

  4. javascript当中静态方法和prototype用法

    6)静态方法和prototype(难) 例 3.6.1 <head>    <meta http-equiv="content-type" content=&qu ...

  5. [JS] ECMAScript 6 - Prototype : compare with c#

    开胃菜 prototype 对象 JavaScript 语言的继承则是通过“原型对象”(prototype). function Cat(name, color) { // <----构造函数 ...

  6. isPrototypeOf&&getPrototypeOf

    在JavaScript这个一切皆为对象的世界里,难免会判断原型链的问题.那么我们就有必要了解了解isPrototypeOf和getPrototypeOf这两个方法咯. 1.isPrototypeOf ...

  7. js call()和apply()

    一.call()和apply(),实例如下: function add(a,b) {     alert(a+b); } function sub(a,b) {     alert(a-b); } a ...

  8. ES6对象扩展

    前面的话 随着JS应用复杂度的不断增加,开发者在程序中使用对象的数量也在持续增长,因此对象使用效率的提升就变得至关重要.ES6通过多种方式来加强对象的使用,通过简单的语法扩展,提供更多操作对象及与对象 ...

  9. Day046--JavaScript-- DOM操作, js中的面向对象, 定时

    一. DOM的操作(创建,追加,删除) parentNode 获取父级标签 nextElementSibling 获取下一个兄弟节点 children 获取所有的子标签 <!DOCTYPEhtm ...

随机推荐

  1. 【互动问答分享】第18期决胜云计算大数据时代Spark亚太研究院公益大讲堂

    Q1:Master和Driver的是同一个东西吗? 两者不是同一个东西,在Standalone模式下Master是用于集群资源管理和调度的,而Driver适用于指挥Worker上的Executor通过 ...

  2. scrapy xpath 从response中获取li,然后再获取li中img的src

    lis = response.xpath("//ul/li") for li in lis: src = li.xpath("img/@src") # 如果xp ...

  3. codeforces-455A

    题目连接:http://codeforces.com/contest/455/problem/A A. Boredom time limit per test 1 second memory limi ...

  4. B - ACM小组的古怪象棋 【地图型BFS+特殊方向】

    ACM小组的Samsara和Staginner对中国象棋特别感兴趣,尤其对马(可能是因为这个棋子的走法比较多吧)的使用进行深入研究.今天他们又在 构思一个古怪的棋局:假如Samsara只有一个马了,而 ...

  5. 【LeetCode刷题】SQL-Combine Two Tables

    Table: Person +-------------+---------+ | Column Name | Type | +-------------+---------+ | PersonId ...

  6. struts2核心配置之struts.xml

    struts.xml -常量配置 -包配置 -包含配置 一.常量配置 struts2常量的配置通常采用三种方式: 1.在struts.xml中使用<constant>元素配置常量 < ...

  7. 【Ajax】PHP中ajax的基本知识点

    Ajax常用属性和方法: 属性: readyState: 0(开始创建ajax对象)1(调用open方法)2(调用send方法)3(正在返回数据)4(返回数据结束) responseText/resp ...

  8. 洛谷 P3041 [USACO12JAN] Video Game Combos

    题目描述 Bessie is playing a video game! In the game, the three letters 'A', 'B', and 'C' are the only v ...

  9. 【强连通分量缩点】【记忆化搜索】bzoj1589 [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果

    缩成DAG f(i)表示以i为起点的最长路 #include<cstdio> #include<cstring> #include<algorithm> #incl ...

  10. 【二维树状数组】bzoj1452 [JSOI2009]Count

    权值的种类只有100种,对每种开个二维BIT,然后是经典操作. #include<cstdio> using namespace std; ][]; struct BIT_2D { ][] ...