---
title: "请教一个js的prototype机制的问题"
author: "ajaxgo"
date: "2007-09-07T11:16:43Z"
tags: ["prototype"]
categories: ["Web前端"]
slug: "js-prototype"
draft: false
lastmod: "2007-09-07T11:16:43Z"
id: 121589
url: "https://ajaxgo.iteye.com/blog/121589"
---

在看一篇js的论文时，看见这么一段话：  
When reading property p of object x using the expression x.p, the object x is searched first for a property named p. If there is one, its value is returned; if not, x’s prototype (let’s call it y) is searched for a property named p. If there isn’t one, y’s prototype is searched next and so on. If no property at all is found, the result is the value undefined.

于是，我用下面的代码测试了下：

js 代码

1. var a=function() {} ;
2. a.prototype=function() {} ;
3. a.prototype.prototype.test='a';
4. var b=new a();
5. alert(b.test);

但，并没有如文中所说那样，b.test还是undefined  
不知道是我理解错了那段话，还是这段话是错的，希望有人来给我指点迷津，谢谢！