JS中的_proto_
var grandfather = function(){
this.name = "LiuYashion"
this.age = ;
} var father = function(){};
father.prototype = new grandfather(); //继承父类
father.game = "LOL"; father.prototype.constructor = father; // 这声明相当于它自己独立出来 // 这里是给father添加额外属性,father.prototype.game是给father的原型grandfather添加额外属性
// 没有通过prototype继承的变量是无法继承的,即子类son中没有game属性 var son = function(){};
son.prototype = new father(); var temp1 = new grandfather();
console.log(temp1.__proto__); //object
console.log(grandfather.prototype) //object var temp2 = new father();
console.log(temp2.__proto__) //grandfather {name: "LiuYashion;", age: 23}
console.log(father.prototype) //grandfather {name: "LiuYashion", age: 23} // son var temp3 = new son();
console.log(son.prototype) // father {}一个原型链
console.log(temp3.__proto__) // father,因为上面黑粗体代码,让son类访问proto时只能指向father,不再是没写时的grandfather,相当于改变了此条原型链的基类
JS中的_proto_的更多相关文章
- JS中的_proto_(2)
function God(){} function Foo(){ this.name="Foo~~"; } Foo.prototype = new God(); function ...
- JS中原型链中的prototype与_proto_的个人理解与详细总结
1.对象的内部属性[[prototype]]和属性__proto__:每个对象都具有一个名为__proto__的属性: 2.函数的属性prototype:每个构造函数(构造函数标准为大写开头,如Fun ...
- 关于JS中原型链中的prototype与_proto_的个人理解与详细总结
一直认为原型链太过复杂,尤其看过某图后被绕晕了一整子,今天清理硬盘空间(渣电脑),偶然又看到这图,勾起了点回忆,于是索性复习一下原型链相关的内容,表达能力欠缺逻辑混乱别见怪(为了防止新人__(此处指我 ...
- JS中原型链中的prototype与_proto_的个人理解与详细总结(**************************************************************)
一直认为原型链太过复杂,尤其看过某图后被绕晕了一整子,今天清理硬盘空间(渣电脑),偶然又看到这图,勾起了点回忆,于是索性复习一下原型链相关的内容,表达能力欠缺逻辑混乱别见怪(为了防止新人__(此处指我 ...
- 《JS中的面向对象技术》
内容要点: 1.什么是对象:JS权威指南学习总结-第六章 ,(有句话:一切都是对象) 2.什么面向对象 使用对象时,只关注对象提供的功能,不关注其内部细节,比如jQuery.面向对象是一种通用思想,并 ...
- 帮你彻底搞懂JS中的prototype、__proto__与constructor(图解)
作为一名前端工程师,必须搞懂JS中的prototype.__proto__与constructor属性,相信很多初学者对这些属性存在许多困惑,容易把它们混淆,本文旨在帮助大家理清它们之间的关系并彻底搞 ...
- 【JavaScript】js 中一些需要注意的问题
关于js中逻辑运算符 sort()方法 1. 关于js中逻辑运算符:|| 和 && 在js逻辑运算中,0."".null.false.undefined.NaN都会 ...
- JS中原型链的理解
new操作符具体干了什么呢?其实很简单,就干了三件事情. var obj = {}; obj.__proto__ = Base.prototype; Base.call(obj); 第一行,我们创建了 ...
- Js中的prototype的用法一
一 prototype介绍 prototype对象是实现面向对象的一个重要机制.每个函数也是一个对象,它们对应的类就是function,每个函数对象都具有一个子对象prototype.Prototyp ...
随机推荐
- three.js透视投影照相机
透视投影照相机(Perspective Camera)的构造函数是: THREE.PerspectiveCamera(fov, aspect, near, far) 让我们通过一张透视照相机投影的图来 ...
- HD1394 Minimum Inversion Number
这道题目的意思是:给你一个序列,统计一开始的逆序数的个数,然后依次把第一个元素放到序列末尾,求每次的逆序数个数,求出每次求逆序数里,逆序数最小的那个数 这里需要推一个递推式,就是每次你把第一个元素放到 ...
- uva748 - Exponentiation
import java.io.*; import java.text.*; import java.util.*; import java.math.*; public class Exponenti ...
- C++可能出错的小细节
1. for(list<Geometry_line>::iterator it = G.begin(); it != G.end();) { if(IsLineCrossed(*it, l ...
- 配置FastDFS
一.安装 (一)下载FastDFS安装包 FastDFS官方论坛:http://www.csource.org 下载1:http://sourceforge.net/projects/fastdfs/ ...
- Codeforces Round #247 (Div. 2) B - Shower Line
模拟即可 #include <iostream> #include <vector> #include <algorithm> using namespace st ...
- Codeforces Round #228 (Div. 2) B. Fox and Cross
#include <iostream> #include <string> #include <vector> #include <algorithm> ...
- Codeforce - Rock-Paper-Scissors
Rock-Paper-Scissors is a two-player game, where each player chooses one of Rock, Paper, or Scissors. ...
- SRM 595 DIV1 250
挺简单的组合把. #include <cstdio> #include <cstring> #include <iostream> #include <vec ...
- UVA 11609 - Teams(二项式系数)
题目链接 想了一会,应该是跟二项式系数有关系,无奈自己推的式子,构不成二项式的系数. 选1个人Cn1*1,选2个人Cn2*2....这样一搞,以为还要消项什么的... 搜了一下题解,先选队长Cn1,选 ...